package if_switch;
import java.util.Scanner;
import java.util.Random;
public class demo11 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;
int score=0;
while(i<5) {
int inputNum,num;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入0,1,2,分别代表石头剪刀布");
inputNum=scanner.nextInt();
Random rand=new Random();
num = rand.nextInt(3);
//num =(int)(Math.random()*10)%3;//生成0-2之间的随机数
System.out.println("庄家出"+num);
if(inputNum==0&&num==1||inputNum==1&&num==2||inputNum==2&&num==0) {
System.out.println("您赢了");
score+=1;
}else if(inputNum==num) {
System.out.println("打平了");
}else {
System.out.println("您输了");
}
i++;
}
System.out.println("得分为:"+score);
}
}
网友评论