Код: Выделить всё
Scanner sc = new Scanner(System.in);
System.out.println("Hey player enter your name");
String name = sc.nextLine();
name = name.toLowerCase();
int human_score=0;
int pc_score=0;
System.out.println("How many rounds u want to play "+name);
byte rounds = sc.nextByte();
if (rounds>10){
System.out.println("Please choose up to 10 rounds. Above is not allowed");
System.out.println("Exiting the game");
System.exit(0);
}
int i =1;
while (i System.out.println("You choose rock");
case 2 -> System.out.println("You choose paper");
case 3 -> System.out.println("You choose scissors");
default -> {
System.out.println("Invalid Choice");
}
}
switch (pc) {
case 1 -> System.out.println("I choose rock");
case 2 -> System.out.println("I choose paper");
case 3 -> System.out.println("I choose scissors");
}
if (human == pc) {
System.out.println("Its a draw");
} else if (human == 1 && pc == 2) {
System.out.println("You lost. Better luck next time");
pc_score+=1;
} else if (human == 1) {
System.out.println("Congrats. You won.");
human_score+=1;
} else if (human == 2 && pc == 1) {
System.out.println("Congrats. You won.");
human_score+=1;
} else if (human == 2) {
System.out.println("You lost. Better luck next time");
pc_score+=1;
} else if (human == 3 && pc == 1) {
System.out.println("You lost. Better luck next time");
pc_score+=1;
} else if (human == 3) {
System.out.println("Congrats. You won.");
human_score+=1;
}
i+=1;
}
if (human_score==pc_score){
System.out.println("Its a draw. Wanna play again?");
} else if(human_score>pc_score){
System.out.println("Congrats you won. Wanna challenge again?");
}else System.out.println("Skill issue. This code is fine");
System.out.println("PC\t"+name+"\n"+pc_score+"\t"+human_score);
Подробнее здесь: https://stackoverflow.com/questions/787 ... op-in-java
Мобильная версия