• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First "99 Bottles of beer script" not working  RSS feed

 
Tom Never
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hand typed in the page 14 script for "99 bottles of beer" and it won't compile, says line 9(While (beerNum > 0) is wrong. What did I do wrong?
thanks,
Tom

C:\Documents and Settings\3441\My Documents\working_java>javac BeerSong.java
BeerSong.java:9: ';' expected
{
^
1 error

C:\Documents and Settings\3441\My Documents\working_java>

here is what I typed in:
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try "while" (lower case 'w')
 
Tom Never
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yay! that was it. thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!