我这什么情况 第十一行好像说什么不能变量 我前面已经包guess定义了啊,搞不懂,有没有懂的老哥 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 找你现在这么写,一旦不等于的时候,就会打印Guess那一句,while方法体里面又没有改变guess的值,就会出现一旦while循环不等于(guess!=theNumber)条件成立,就会进入大于Guess语句哪里,形成死循环。参考下面代码,改变guess的值就可以了。public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int theNumber = (int) (Math.random() * 100 + 1); int guess = 0; while(guess!=theNumber){ System.out.println("Guess ..."); guess = scanner.nextInt(); } System.out.println("You ..."); } 明白了,就是我少了一组大括号把while括起来是吗,发完帖子我就出门了,等我回去再试试看 你上面定义的是theNumber,下面while里是tehNumber,当然会报没定义参数啊。细心一点。 theNumber变量名称错误!必须报错! the错了吧,仔细点阚啊 日期计算 各位高手帮我看看2个方法运行结果中哪个更占内存?为什么? JAVABEAN是什么? 可以在哪一些场合下用呢? 如何用JAVA写一个客户端程序,实现对远程数据库的监听。 oracle jdbc的问题 当午接分 如何实现当鼠标移出JTable区域,并且click一下,触发一个事件? 初学者问题 为什么会是这样???? java几个基础问题? 新人求教 Java初学者基础算法题求解
Scanner scanner = new Scanner(System.in);
int theNumber = (int) (Math.random() * 100 + 1);
int guess = 0;
while(guess!=theNumber){
System.out.println("Guess ...");
guess = scanner.nextInt();
}
System.out.println("You ...");
}
细心一点。