以下代码输出错误

时间:2017-12-12 03:54:10

标签: java

此代码的输出应该从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 个答案:

答案 0 :(得分:0)

我认为Dawood已经给出了最合理的答案。您的输出窗口是有限的。我刚刚在Linux提示符下执行了你的代码,当我滚动完成时,它真的从99开始。

enter image description here