名古屋のしがない奴の落書き帳
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
public class sJ{
public static final int STONE = 0;
public static final int SCISSORS = 1;
public static final int PAPER = 2;
public static void main(String[] args){
int player1WinCount = 0;
int player2WinCount = 0;
System.out.println("【ジャンケン開始】\n");
for(int cnt=0;cnt<3;cnt++){
double randomNum = 0;
int player1Hand = 0;
System.out.println("【第"+(cnt+1)+"回戦】");
randomNum = Math.random() * 3;
if (randomNum < 1){
player1Hand = STONE;
System.out.print("グー");
}else if(randomNum < 2){
player1Hand = SCISSORS;
System.out.print("チョキ");
}else if(randomNum < 3){
player1Hand = PAPER;
System.out.print("パー");
}
System.out.print(" v.s. ");
int player2Hand = 0;
randomNum = Math.random() * 3;
if (randomNum < 1){
player2Hand = STONE;
System.out.print("グー");
}else if(randomNum < 2){
player2Hand = SCISSORS;
System.out.print("チョキ");
}else if(randomNum < 3){
player2Hand = PAPER;
System.out.print("パー");
}
if( (player1Hand == STONE && player2Hand == SCISSORS)
|| (player1Hand == SCISSORS && player2Hand == PAPER)
|| (player1Hand == PAPER && player2Hand == STONE) )
{
player1WinCount++;
System.out.println("\n プレイヤー1が勝ちました! \n");
}else if( (player1Hand == STONE && player2Hand == PAPER)
|| (player1Hand == SCISSORS && player2Hand == STONE)
|| (player1Hand == PAPER && player2Hand == SCISSORS)
){
player2WinCount++;
System.out.println("\n プレイヤー2が勝ちました! \n");
}else{
System.out.println("\n 引き分けです! \n");
}
}
System.out.println("【ジャンケン終了!】");
if(player1WinCount > player2WinCount){
System.out.println(player1WinCount+"対"+player2WinCount+"でプレイヤー1の勝ちです!\n");
}else if(player1WinCount < player2WinCount){
System.out.println(player1WinCount+"対"+player2WinCount+"でプレイヤー2の勝ちです!\n");
}else if(player1WinCount > player2WinCount){
System.out.println(player1WinCount+"対"+player2WinCount+"で引き分けです!\n");
}
}
}
PR
この記事にコメントする