public static void main(String[] args) {
System.out.println("开始游戏\n石头---1\n剪子---2\n布---3\n请输入:\n");
Scanner sc = new Scanner(System.in);
int option =sc.nextInt();//剪刀1,石头2,布3
Random random = new Random();
int randomNumber = random.nextInt(3) + 1; // 生成 0 到 2 的随机数,然后加 1 得到 1 到 3
switch (option) {
case 1:
switch (randomNumber) {
case 1:
System.out.println("平局");
System.out.println("你出石头,电脑出石头");
break;
case 2:
System.out.println("你赢了");
System.out.println("你出石头,电脑出剪刀");
break;
case 3:
System.out.println("你输了");
System.out.println("你出石头,电脑出布");
break;
}
break;
case 2:
switch (randomNumber) {
case 1:
System.out.println("你输了");
System.out.println("你出剪刀,电脑出石头");
break;
case 2:
System.out.println("平局");
System.out.println("你出剪刀,电脑出剪刀");
break;
case 3:
System.out.println("你赢了");
System.out.println("你出剪刀,电脑出布");
break;
}
break;
case 3:
switch (randomNumber) {
case 1:
System.out.println("你赢了");
System.out.println("你出布,电脑出石头");
break;
case 2:
System.out.println("你输了");
System.out.println("你出布,电脑出剪刀");
break;
case 3:
System.out.println("平局");
System.out.println("你出布,电脑出布");
break;
}
break;
default:
System.out.println("输入错误");
}