在我的第二个if/else语句中有一个小故障,我想,你能帮我找到它吗?

-3 java

在我的第二个if/else语句中有一个小故障,我想,你能帮我找到它吗?曾经的单词== 1单词的值应该改为"瓶子",但它正在打印"瓶子".


public class milkSong
{
    public static void main(String[] args) {
        int milkNum = 10; //decreased the bottles of milk so that the output would fit
        String word = "bottles";

        while (milkNum > 0) {

            if (milkNum == 1) { 
                word = "bottle"; 
            }

            System.out.println (milkNum + " " + word + " of milk on the wall.");
            System.out.println (milkNum + " " + word + " of milk.");
            System.out.println ("Take one down.");
            System.out.println ("Pass it around.");
            milkNum = milkNum - 1;

           //There is a problem with this statement, once beerNum == 1, still printing "bottles"
            if (milkNum > 0) { 
                System.out.println (milkNum + " " + word + " of milk on the wall.");
            } 
            else {
                System.out.println ("No more bottles of milk on the wall.");
            }

        }

    }
}
Run Code Online (Sandbox Code Playgroud)

Mil*_*ilk 6

移动的设置word是后milkNum = milkNum -1

  • "牛奶"用户解决"瓶装牛奶"问题.好的.:) (2认同)