public class BeerSong { public static void main(String args[]) { int BeerNum = 99; String word = "bottles"; while(BeerNum > 0) { System.out.println(BeerNum + " " + word + " of the beer on the wall"); System.out.println("Catch one."); System.out.println("Take around."); BeerNum = BeerNum - 1; if(BeerNum == 1) { word = "bottle"; } if(BeerNum > 0) { System.out.println(BeerNum + " " + word + " of the beer on the wall"); } else { System.out.println("Nothing on the wall"); } } } } The question itself is about:
if(BeerNum == 1) word = "bottle"; } If you put it right after the while, then at the end it will be like this: 1 bottles of beer on the wall. 1 bottle of beer on the wall.
Why is the plural value taken for the first line, and the only one for the second? At the same time, if you put this if statement after BeerNum = BeerNum - 1; then both values will be in the singular. Explain. Why such difference? Is there a difference where to put if at the beginning of a block of code or after decreasing? Thank!
различие, где ставить if в начале блока кода или после уменьшения?- Do not you think that you yourself answered the question? - Alexey Shimansky