• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with command prompt.

 
Justin Krawczak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having an issue with the command prompt, I have done a helloworld.class and run it, and it outputs hello world obviously, but then i wrote this.



It compiles, and seems to run, but the command prompt shows nothing. Any advice? I tried to change the buffer size on the command prompt much higher but I still get nothing. I even attempted to lower the number of bottles form 99 to 10 like you see above.
 
Stephan van Hulst
Bartender
Pie
Posts: 5888
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should probably run BeerSong, not helloworld.
 
Justin Krawczak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running BeerSong. Sorry for the miscommunication at the top. I was saying that I had done the helloworld previously. Again I will re-iterate. I wrote the BeerSong tutorial, the code is attached, I recieved a couple error messages when compiling it the first time, fixed the errors, and got it to compile. When I try to run BeerSong via java BeerSong the program or "class" runs, and nothing prints out on the command prompt. I attempted to increase the buffer size to allow more text, that didnt work either. I then attempted to lower the starting int for BeerSong to 10, in an attempt to cut down on the output. Re-compiled it. Attempted to run it and the same, it runs and cursor sits a line below, nothing prints on the command prompt.
 
Stephan van Hulst
Bartender
Pie
Posts: 5888
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a very close look at line 6.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The semicolon on this line doesn't belong there, and it's the whole problem:

while (beerNum > 0);

This line could be translated into English as "If beerNum is greater than zero, do nothing, then check beerNum again. If it's greater than zero, do nothing, then check again. And so on, and so on, forever." That lone semicolon is an empty statement -- a valid line of Java code that does nothing, and it's the body of the while loop. Since the variable never changes by doing nothing, nothing ever happens.

What you actually want is for the big blob of code in brackets to be the body of the loop. Take that semicolon out, and it will be!
 
Justin Krawczak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both very much. I've been staring at this thing for hours possibly why I couldn't see it. Esentially I was making while a statement. SMASH HEAD ON DESK! Honestly, thank you both for pointing it out.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

The semicolon after while ( . . . ) is something your teacher ought to have warned you about. It means simply "do nothing", so you get an infinite loop and never get to the "print" statements.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic