package hello;
import java.util.Scanner;
public class Ademo03 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int number=(int)(Math.random()*100+1);
int a;
int count=0;
do{
a=in.nextInt();
count=count+1;
if(a>number) {
System.out.println("偏大");
}
else if(a<number) {
System.out.println("偏小");
}
}while(a!=number);
System.out.println("恭喜你猜对了,你猜了"+count+"次");
}
}
猜数游戏
最新推荐文章于 2022-11-25 09:37:58 发布
本文介绍了一个简单的Java猜数字游戏程序。程序使用Scanner类接收用户输入,并通过Math.random()生成1到100之间的随机数。游戏过程中,会根据用户的猜测给出偏大或偏小的提示,直到猜中为止。
3127

被折叠的 条评论
为什么被折叠?



