找你现在这么写,一旦不等于的时候,就会打印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 ..."); }
62,612
社区成员
307,332
社区内容
加载中
试试用AI创作助手写篇文章吧