0
Correct the following code:
// classic childern's favorite"99 bottles of beer" public class BeerSong { public static void main (String[] args) { int beerNum = 99; String word = “bottles”; while (beerNum > 0) { if (beerNum == 1) { word = “bottle”; // singular, as in ONE bottle. } System.out.println(beerNum + “ ” + word + “ of beer on the wall”); System.out.println(beerNum + “ ” + word + “ of beer.”); System.out.println(“Take one down.”); System.out.println(“Pass it around.”); beerNum = beerNum - 1; if (beerNum > 0) { System.out.println(beerNum + “ ” + word + “ of beer 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
4 ответов
+ 7
Oh I found it! Your inverted commas!
+ 5
Let me look into this. Also weird rhyme.
+ 4
You are using special double quotes for your strings, that will fail the compiler to parse your code, because the strings aren't properly wrapped in quotes. Is this what you mean by one little flaw?
P.S. Indentation is another "flaw" though 😁
+ 1
There’s still one little flaw in our
code. It compiles and runs, but the
output isn’t 100% perfect. See if
you can spot the flaw , and fix it.