java随机数
作者:互联网
public class LHJGame {
//alt+/ 智能补全 main方法就是启动项
public static void main(String[] args) throws Exception {
int coin=100;
System.out.println("剩余币数:"+coin);
for (int i = 0; i < 10; i++) {
//换行输出字符串到控制台
System.out.println("请输入投币数:");
//sc是一个专门用来获取键盘输入信息的类型
Scanner sc = new Scanner(System.in);
int b=sc.nextInt();
coin=coin-b;
Random rd=new Random();
int r1=rd.nextInt(9)+1;
int r2=rd.nextInt(9)+1;
int r3=rd.nextInt(9)+1;
System.out.println("*******");
System.out.println("*"+r1+":"+r2+":"+r3+"*"+"!");
System.out.println("*******");
if(r1==7&&r2==7&&r3==7){
coin=coin+b*10;
System.out.println("恭喜你获得"+b*10+"的货币");
}else if(r1==r2&&r1==r3){
coin=coin+b*3;
System.out.println("恭喜你获得"+b*3+"的货币");
}else{
System.out.println("谢谢惠顾");
}
System.out.println("剩余币数:"+coin);
}
}
}
标签:java,r1,int,System,随机数,println,coin,out 来源: https://www.cnblogs.com/adolup/p/15993261.html