public static void main(String args[]) {
System.out.print("请出拳【石头/剪刀/布】:");
Scanner scanner = new Scanner(System.in);
String aList[] = { "剪刀", "石头", "布" };
String userInput = scanner.nextLine();
String systemInput = aList[new Random().nextInt(3)];
int userInt = switch (userInput) {
case "石头" -> 0;
case "剪刀" -> 1;
case "布" -> 2;
default -> {yield 100;}
};
int systemInt = switch (systemInput) {
int result = systemInt - userInt;
switch (result) {
case -98, -99, -100 -> System.out.println("请正确出拳!");
case -1, 2 -> System.out.printf("系统出:%s 你输了!", systemInput);
case 0 -> System.out.printf("系统也是出:%s 打平了!", systemInput);
default -> System.out.printf("系统出:%s 你赢了!", systemInput);
}
Sign in to make a reply
陆佩廷
public static void main(String args[]) {
System.out.print("请出拳【石头/剪刀/布】:");
Scanner scanner = new Scanner(System.in);
String aList[] = { "剪刀", "石头", "布" };
String userInput = scanner.nextLine();
String systemInput = aList[new Random().nextInt(3)];
int userInt = switch (userInput) {
case "石头" -> 0;
case "剪刀" -> 1;
case "布" -> 2;
default -> {yield 100;}
};
int systemInt = switch (systemInput) {
case "石头" -> 0;
case "剪刀" -> 1;
case "布" -> 2;
default -> {yield 100;}
};
int result = systemInt - userInt;
switch (result) {
case -98, -99, -100 -> System.out.println("请正确出拳!");
case -1, 2 -> System.out.printf("系统出:%s 你输了!", systemInput);
case 0 -> System.out.printf("系统也是出:%s 打平了!", systemInput);
default -> System.out.printf("系统出:%s 你赢了!", systemInput);
}
}