2017-12-12 5 views
-8

このコードの出力は99から開始されますが、形式59が開始されます。その理由は何ですか? ここにコード下のコードの出力が間違っています

public class BeerSong { 
    public static void main(String[] args) { 
     int x = 99; 
     String word = "bottles"; 
     while (x > 0) { 
      if (x == 1) { 
       word = "bottle"; // singular, as in ONE bottle. 
      } 
      System.out.println(x + "" + word + " of beer on the wall"); 
      System.out.println(x + "" + word + " of beer."); 
      System.out.println("Take one down."); 
      System.out.println("Pass it around."); 
      x = x - 1; 
      if (x > 0) { 
       System.out.println(x + "" + word + " of beer2 on the wall"); 
      } else { 
       System.out.println("No more bottles of beer on the wall"); 
      } // end else 
     } // end while loop 
    } // end main method 
} // end class 
+1

[これは、99から始めない](https://ideone.com/P2jnGR) – shmosel

+5

コンソールに表示される行数に制限はありますか?おそらく、その曲の一部が上からスクロールしています。 –

+0

netbeansでは正しく動作しますが、コマンドプロンプトでは正しく動作しません –

答えて

0

私はDawoodがすでにもっともらしい答えを与えてくれたと思います。出力ウィンドウには制限があります。私はLinuxのプロンプトでコードを実行され、私が完了スクロールするとき、それは本当にから始まり99

enter image description here