虽然循环在java中不起作用

时间:2016-03-02 19:32:52

标签: java loops while-loop

我的代码不会正确执行while循环,它只会询问用户输入。我的代码中的错误在哪里?

  int number = 0;

  int maxNumber;
  Scanner keyboard = new Scanner(System.in);
  System.out.print("Enter a positive number greater than 0: ");
  maxNumber = keyboard.nextInt();

     while (number < maxNumber);
     {
        number++;
        System.out.print(number);
     }

2 个答案:

答案 0 :(得分:1)

应该是:

 while (number < maxNumber){
    number++;
    System.out.print(number);
 }

请注意错误的分号。

答案 1 :(得分:1)

这里有一个半冒号

 while (number < maxNumber); ///<----

应该是:

 while (number < maxNumber){
    number++;
    System.out.print(number);
 }