System.out.println("please choice:"); System.out.println(" 1: Rock"); System.out.println(" 2: Scissors"); System.out.println(" 3: Paper"); // 用户输入: int choice = 0; Scanner sc = new Scanner(System.in); System.out.print("choice:"); choice = sc.nextInt(); // 计算机随机数 1, 2, 3: int random = (int) (1 + Math.random() * 3); boolean isWin = false; boolean isDraw = false; int result = random - choice; switch (choice) { case 1: case 2: isWin = result == 1 ? true : false; isDraw = result == 0 ? true : false; break; case 3: isWin = result == -2 ? true : false; isDraw = result == 0 ? true : false; break; } if (isDraw) { System.out.println("Draw"); }else if (isWin) { System.err.println("you win"); }else { System.out.println("you lose"); }
Sign in to make a reply
灵逗士