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



我的第二个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.");
}
}
}
}

word的设置移动到milkNum = milkNum -1之后

相关内容

最新更新