import java.util.Scanner;
public class Test{
public static void main(String[] args){
String[] status = {"?", "石头", "剪刀", "布"};
String[] r = {"无结果", "胜利", "输了", "平局"};
Scanner scanner = new Scanner(System.in);
System.out.print("1 代表石头\n2 代表剪刀\n3 代表布\n请输入数字:");
int choice = scanner.nextInt();
int random = 1 + (int) (Math.random() * 3);
int res = 0;
switch (choice){
case 1:
res = random==1?3:random==2?1:2;
break;
case 2:
res = random==1?2:random==2?3:1;
break;
case 3:
res = random==1?1:random==2?2:3;
break;
default:
choice = 0;
}
System.out.printf("对方出了%s,而你出了%s,所以比赛%s。", status[random], status[choice], r[res]);
}
}
XiaoLa_BILIBILI