public class demo3 {
public static void main(String[] args) {
//猜数字
System.out.print("请从键盘输入(1~100)之内的数:");
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("你猜的数字偏小");
}
System.out.print("请重新输入");
}while (a!=number);
System.out.println("恭喜你猜对了,你猜了"+count+"次");
}
}
猜数字(100之内的数字)
最新推荐文章于 2024-09-03 20:17:53 发布