概述
import java.util.*;
public class hhh {
public static void main(String[] args) {
Random ran = new Random();
int num = ran.nextInt(51) + 50;
int guess;
int count = 0;
Scanner input = new Scanner(System.in);
System.out.println("请猜一个50-100的整数");
do {
guess=input.nextInt();
if (guess > num)
System.out.println("你猜大了,再猜小一点");
else
if (guess < num)
System.out.println("你猜小了,再猜大一点");
else {
System.out.println("恭喜你猜对了");
break;
}
count++;
System.out.println("你的剩余"+(5-count)+"次机会");
}while (count < 5) ;
}
}
最后
以上就是重要大门为你收集整理的do-while猜数字的全部内容,希望文章能够帮你解决do-while猜数字所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复