import java.util.Scanner;
public class Exercise1 {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
boolean flag=true;
int random=0;
int number=0;
int count=0;
int right=0;
int wrong=0;
random=(int)(Math.random()*100);
while (flag) {
System.out.println("系统将产生一个0~100之间的随机整数,但不包括100,你来猜一猜吧!");
System.out.println("请输入你猜的数:");
number=input.nextInt();
count=count+1;
if (number>random){
wrong=wrong+1;
System.out.println("你猜的太大了!");
System.out.println("你目前猜了"+count+"次了!"+"你猜对了"+right+"次!"+"你猜错了"+wrong+"次!\n");
}else if (number<random){
wrong=wrong+1;
System.out.println("你猜的太小了!");
System.out.println("你目前猜了"+count+"次了!"+"你猜对了"+right+"次!"+"你猜错了"+wrong+"次!");
}else{
right=right+1;
System.out.println("你终于猜对了!");
System.out.println("你目前猜了"+count+"次了!"+"你猜对了"+right+"次!"+"你猜错了"+wrong+"次!");
break;
}
}
if (count<=5){
System.out.println("太厉害了!天才啊!");
}else if (count<=10){
System.out.println("很牛啊!高手!");
}else if (count<=15){
System.out.println("还不错啊!");
}else {
System.out.println("笨!这么慢!");
}
}
}
猜数游戏
最新推荐文章于 2024-11-22 20:01:41 发布