import java.util.Scanner;
/**
* @Author : Sakura
* @Demo : "用switch语句实现石头剪子布游戏 "
* @Date : Create in 11:47 2020/6/29
* @Modified : " "
*/
public class switch石头剪子布 {
public static void main(String[] args) {
System.out.print("请输入对应的数字来进行猜拳: ");
System.out.print("1: 石头");
System.out.print("2: 剪刀");
System.out.print("3: 布");
System.out.println(": ");
Scanner scanner = new Scanner(System.in);
int choose = scanner.nextInt();
// 随机数
int random = 1 + (int)Math.random() * 3; //生成1-3的随机数
switch (choose){
case 1:
if (choose == 1) {
System.out.println("您选择的数字是1,对应的是石头,\n对手出的是布,您输了");
break;
}
case 2:
if(choose == 2) {
System.out.println("您选择的数字是2,对应的是剪刀,\n对手出的是布,您赢了");
case 3:
if (choose == 3) {
System.out.println("您选择的数字是3,对应的是布,\n对手出的是剪刀,您输了");
default:
System.out.println("超出游戏规则");
Sign in to make a reply
神樂坂Dino
import java.util.Scanner;
/**
* @Author : Sakura
* @Demo : "用switch语句实现石头剪子布游戏 "
* @Date : Create in 11:47 2020/6/29
* @Modified : " "
*/
public class switch石头剪子布 {
public static void main(String[] args) {
System.out.print("请输入对应的数字来进行猜拳: ");
System.out.print("1: 石头");
System.out.print("2: 剪刀");
System.out.print("3: 布");
System.out.println(": ");
Scanner scanner = new Scanner(System.in);
int choose = scanner.nextInt();
// 随机数
int random = 1 + (int)Math.random() * 3; //生成1-3的随机数
switch (choose){
case 1:
if (choose == 1) {
System.out.println("您选择的数字是1,对应的是石头,\n对手出的是布,您输了");
break;
}
case 2:
if(choose == 2) {
System.out.println("您选择的数字是2,对应的是剪刀,\n对手出的是布,您赢了");
break;
}
case 3:
if (choose == 3) {
System.out.println("您选择的数字是3,对应的是布,\n对手出的是剪刀,您输了");
break;
}
default:
System.out.println("超出游戏规则");
break;
}
}
}