import java.util.Scanner; /** * switch实现石头/剪子/布并判断胜负 */ public class Main { public static void main(String[] args) { System.out.println("please choice:"); System.out.println(" 1: Rock"); System.out.println(" 2: Scissors"); System.out.println(" 3: Paper"); Scanner scanner = new Scanner(System.in); // 用户输入: int choice = scanner.nextInt(); // 计算机随机数 1, 2, 3: int random = 1 + (int) (Math.random() * 3); switch (choice) { case 1 -> System.out.println(random==1?"平局!":random==2?"你赢了!":"你输了!"); case 2 -> System.out.println(random==2?"平局!":random==3?"你赢了!":"你输了!"); case 3 -> System.out.println(random==3?"平局!":random==1?"你赢了!":"你输了!"); default -> System.out.println("选择错误!"); } } }
Sign in to make a reply
lshgly