Java编程题,猜数字游戏,我刚学的第八章适合初学者,用循环和随机数就行。

公共静态void main(String[] args) {

Random ran = new Random();

int random = ran . nextint(100);

System.out.println("此处为随机数,供参考,随机数为"+random ");

System.out.println("请输入你猜到的数字");

int I = 0;

while(我& lt9) {

Scanner sc =新扫描仪(system . in);

int guess = 0;

尝试{

guess = sc . nextint();

} catch(异常e) {

System.out.println("请输入正确的数字");

继续;

}

if(random == guess){

System.out.println("恭喜你猜对");

打破;

}

if(random & lt;猜测){

i++;

system . out . println(" big ");

}

if(random & gt;猜测){

i++;

system . out . println(" small ");

}

}

如果(i & gt=9){

System.out.println("你真笨,下次加油");

}

}