aspose file tools*
The moose likes Beginning Java and the fly likes Problem with command prompt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with command prompt." Watch "Problem with command prompt." New topic
Author

Problem with command prompt.

Justin Krawczak
Greenhorn

Joined: Oct 02, 2010
Posts: 3
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

Joined: Sep 20, 2010
Posts: 3647
    
  17

You should probably run BeerSong, not helloworld.
Justin Krawczak
Greenhorn

Joined: Oct 02, 2010
Posts: 3
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

Joined: Sep 20, 2010
Posts: 3647
    
  17

Take a very close look at line 6.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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!


[Jess in Action][AskingGoodQuestions]
Justin Krawczak
Greenhorn

Joined: Oct 02, 2010
Posts: 3
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

Joined: Oct 13, 2005
Posts: 39409
    
  28
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with command prompt.