Discuss / Java / 想到一种循环的判断方法

想到一种循环的判断方法

Topic source

黯然

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

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);

System.out.println(random);

//Math.random返回一个[0,1)的double数

switch (choice-random) {

// TODO:

case 1 ->System.out.println("You lose");

case -1 ->System.out.println("You win");

case 2 ->System.out.println("You win");

case -2 ->System.out.println("You lose");

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

default ->System.out.println("Error");

}

}


  • 1

Reply