我是靠谱客的博主 虚心溪流,这篇文章主要介绍“猜数字“游戏,系统随机生成一个[1,100]的数字,由用户输入数字后,计算机提示输入数字“偏大”、“偏小”,并记录猜数次数,现在分享给大家,希望可以做个参考。
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int number = (int) (Math.random()*100+1);
//(0,1)*100=(0,100)+1=[1,100]
int count = 0;
int a;
do {
a = in.nextInt();
if(a>number)
{
System.out.println("偏大");
}
else if (a<number)
{
System.out.println("偏小");
}
count++;
}while(a!=number);
System.out.println("恭喜你猜对了,你猜了"+count+"次");
}
}
最后
以上就是虚心溪流最近收集整理的关于“猜数字“游戏,系统随机生成一个[1,100]的数字,由用户输入数字后,计算机提示输入数字“偏大”、“偏小”,并记录猜数次数的全部内容,更多相关“猜数字“游戏,系统随机生成一个[1,100]内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复