Discuss / Java / 作业,有借鉴评论区,希望自己之后能更好的理解java

作业,有借鉴评论区,希望自己之后能更好的理解java

Topic source

public class Main {

public static void main(String[] args) {

System.out.println("please choice:");

System.out.println(" 1: 石头");

System.out.println(" 2: 剪刀");

System.out.println(" 3: 布");

// 用户输入:

Scanner scanner = new Scanner(System.in);

System.out.print("请选择你要出的手势");

int choice = scanner.nextInt();

// 计算机随机数 1, 2, 3:

switch (choice) {

default:

System.out.println("输入有误,请重新输入");

break;

case 1,2,3:

int random = (int) (1 + Math.random() * 3);

int a = random - choice;

switch (random) {

case 1 -> System.out.println("对方出了:石头");

case 2 -> System.out.println("对方出了:剪刀");

case 3 -> System.out.println("对方出了:布");

}

switch (a) {

case -1,2 -> System.out.println("你输了");

case 1,-2 -> System.out.println("你赢了");

case 0 -> System.out.println("平局");

}

}

}

}

shu_ao_han

#2 Created at ... [Delete] [Delete and Lock User]

加油?


  • 1

Reply