• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with command prompt.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should probably run BeerSong, not helloworld.
 
Justin Krawczak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a very close look at line 6.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic