int result;
Scanner in = new Scanner(System.in);
int number = (int) (Math.random() * (900) + 100);
System.out.println("\n***********猜数码小游戏,你hold得住吗?*********");
System.out.println("\n ********随机数字产生:不告诉你!*********\n");
System.out.println("让我们动动脑筋来猜一猜吧,小提示:他是一个从100到999的整数");
long sTartTime = System.currentTimeMillis();
int count=1;
String breakFlag="N";
while (true) {
System.out.println("请输入你第" + count + "次的猜测");
result = guess(count);
if (result > number)
System.out.println("不好意思,您所猜的数字大于谜底数字!");
else if (result < number)
System.out.println("不好意思,您所猜的数字小于谜底数字!");
else {
SimpleDateFormat sNowDate = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
long sEndTime = System.currentTimeMillis();
System.out.println("\n ***********正确答案:" + number
+ "***************\n");
if (count == 1) {
System.out.println("perfect!!恭喜您!一次就中!!");
} else if (count< 10) {
System.out.println("good job! 您总共猜了" + count + "次, 还要继续加油!!");
} else {
System.out.println("not bad! 您总共猜了" + count + "次, 任重而道远啊!");
}
System.out.println("当前时间 :" + sNowDate.format(new Date()));
System.out.println("所用时间 :" + (sEndTime - sTartTime) / 1000
+ "秒");
System.out.print("恭喜挑战成功!是否继续【Y/N】?");
String answer=in.nextLine();
if(breakFlag.equalsIgnoreCase(answer)){
System.out.println("\n欢迎使用猜数系统!");
in.close();
break;
}else{
count=0;
number = (int) (Math.random() * (900) + 100);
}
}
if(count==10){
System.out.print("您10次都没猜对,游戏已结束,是否继续【Y/N】?");
String answer=in.nextLine();
if(breakFlag.equalsIgnoreCase(answer)){
System.out.println("\n欢迎使用猜数系统!");
in.close();
break;
}else{
count=0;
number = (int) (Math.random() * (900) + 100);
}
}
count++;
}
追问你的这个程序是自动运行的。需要用户输入,再按回车继续的
追答自动运行是什么鬼
追问![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/ac6eddc451da81cbb13aff2d5a66d01608243175?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
我都没有输入数字。您能给我一个完整版的么。重谢
追答本回答被提问者采纳