import java.util.Scanner;
/**
* switch实现石头/剪子/布并判断胜负
*/
public class Switch {
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 sc = new Scanner(System.in);
int choice = sc.nextInt();
// 计算机随机数 1, 2, 3:
int random = 1 + (int) Math.random() * 3;
System.out.println(random);
switch (choice) {
case 1:
switch (random){
System.out.println("Equals!");
break;
case 2:
System.out.println("You Win!");
case 3:
System.out.println("You lose!");
}
System.out.println("You win");
System.out.println("You win!");
Sign in to make a reply
用户5527594890
import java.util.Scanner;
/**
* switch实现石头/剪子/布并判断胜负
*/
public class Switch {
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 sc = new Scanner(System.in);
int choice = sc.nextInt();
// 计算机随机数 1, 2, 3:
int random = 1 + (int) Math.random() * 3;
System.out.println(random);
switch (choice) {
case 1:
switch (random){
case 1:
System.out.println("Equals!");
break;
case 2:
System.out.println("You Win!");
break;
case 3:
System.out.println("You lose!");
break;
}
break;
case 2:
switch (random){
case 1:
System.out.println("You lose!");
break;
case 2:
System.out.println("Equals!");
break;
case 3:
System.out.println("You win");
break;
}
break;
case 3:
switch (random){
case 1:
System.out.println("You win!");
break;
case 2:
System.out.println("You lose!");
break;
case 3:
System.out.println("Equals!");
break;
}
break;
}
}
}