import java.util.*;
class test03
{
public static void main(String[] args){
int score = 0;
for(int i=1;i<=5;i++){
System.out.println("这是第"+i+"轮");
Scanner sr = new Scanner(System.in);
Random r = new Random();
int rd = r.nextInt(50)+1;
//System.out.println(rd+"随机");
System.out.println("请输入一个数");
int sc = sr.nextInt();
if(sc==rd){
System.out.println("恭喜你答对了");
score=score+20;
System.out.println("您的分数为"+score);
continue;
}else{
for(int j=4;j>=1;j--){
if(sc>rd){
System.out.println("这个数比您输入的数小,请重新输入");
System.out.println("这一轮您还有"+j+"机会");
sc = sr.nextInt();
}else if(sc<rd){
System.out.println("这个数比您输入的大,请重新输入");
System.out.println("这一轮还有"+j+"机会");
sc = sr.nextInt();
}else{
System.out.println("恭喜你,终于猜对了");
score=score+20;
System.out.println("您的分数为"+score);
break;
}
}
}
}
}
}
生成随机数,猜数得分
最新推荐文章于 2023-05-04 18:07:44 发布