Scanner scanner = new Scanner(System.in);
System.out.println("scissors(1), rock(2) or cloth(3)");
System.out.print("Input you choose by number: ");
int choose = scanner.nextInt();
int computer = (int)(Math.random() * 3) + 1;
String string1 = switch (choose) {
case 1 -> "scissors";
case 2 -> "rock";
case 3 -> "cloth";
default -> null;
};
if (string1 == null) {
System.out.println("Input error");
System.exit(0);
}
String string2 = switch (computer) {
System.out.println(string1 + " VS " + string2);
switch (choose - computer) {
case 2, 1 -> System.out.println("You win");
case -1, -2 -> System.out.println("Computer win");
default -> System.out.println("Draw");
Sign in to make a reply
PM-Rowlet
Scanner scanner = new Scanner(System.in);
System.out.println("scissors(1), rock(2) or cloth(3)");
System.out.print("Input you choose by number: ");
int choose = scanner.nextInt();
int computer = (int)(Math.random() * 3) + 1;
String string1 = switch (choose) {
case 1 -> "scissors";
case 2 -> "rock";
case 3 -> "cloth";
default -> null;
};
if (string1 == null) {
System.out.println("Input error");
System.exit(0);
}
String string2 = switch (computer) {
case 1 -> "scissors";
case 2 -> "rock";
case 3 -> "cloth";
default -> null;
};
System.out.println(string1 + " VS " + string2);
switch (choose - computer) {
case 2, 1 -> System.out.println("You win");
case -1, -2 -> System.out.println("Computer win");
default -> System.out.println("Draw");