Код: Выделить всё
import java.util.Random;
import java.util.Scanner;
public class HEHE_19_Rock_Paper {
public static void main(String[] args) {
int t = 0;
int w,l;
while (t input = 1;
case "r" -> input = 2;
case "p" -> input = 3;
default ->
throw new IllegalStateException("Unexpected value: " + i + "Only 3 inputs are available 'S','R' and 'P'."); // suggested by Intelli J
}
if (input == 1) {
System.out.println("You Have Picked Scissors!!!");
} else if (input == 2) {
System.out.println("You Have Picked Rock!!!");
} else if (input == 3) {
System.out.println("You Have Picked Paper!!!");
} else {
System.out.println("What are you doing!!! Only 3 inputs are available 'S','R' and 'P'.");
}
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
// Computer Logic of Picking
Random rand = new Random();
int response = rand.nextInt(1, 4);
if (response == 1) {
System.out.println("PC Has Picked Scissors!!!");
} else if (response == 2) {
System.out.println("PC Has Picked Rock!!!");
} else if (response == 3) {
System.out.println("PC Has Picked Paper!!!");
}
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
w = 0;
l = 0;
// Deciding Logic
if (input == response) {
System.out.println("===========The Game is Draw!!!===========");
} else if (input == 1 && response == 2) {
System.out.println("==========PC has won the Game!!==========");
l++;
} else if (input == 2 && response == 3) {
System.out.println("==========PC has won the Game!!==========");
l++;
} else if (input == 3 && response == 1) {
System.out.println("==========PC has won the Game!!==========");
l++;
} else if (response == 1 && input == 2) {
System.out.println("==========You have won the Game!!==========");
w++;
} else if (response == 2 && input == 3) {
System.out.println("==========You have won the Game!!==========");
w++;
} else if (response == 3 && input == 1) {
System.out.println("==========You have won the Game!!==========");
w++;
}
t++;
}
switch(w > l){
case true -> System.out.println("You have won the game!!");
case false -> System.out.println("You have lost the game!!");
default -> System.out.println("The game is Draw");
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... -outside-a