• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

BeerSong Java code

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
this is my first post here, im new to java.

Im learning java using head first 2nd edition book, and i came across this exercise which im having trouble getting the output %100 right

this is the code, and attached is the output










THANKS IN ADVANCE
Output.jpg
[Thumbnail for Output.jpg]
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there :-)

Looks ok to me so far..... what else do you want it to do?

When I did the same project I thought it would be "fancy" to put a blank line between each verse . This is what I did:



And just to let you know, it's good to use code tags around here.... makes it easier to read (and you'll get more responses).
Janeice
 
Marshal
Posts: 80735
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please use the CODE button; since you are new I have gone back to your post and edited it, so you can see how much better it looks. Please use copy-and-paste rather than a screenshot to show your output. Click the icon on the top left of the command prompt window, then edit, then mark, then use mouse to highlight, then enter key.

I couldn't read the full output, so I copied and executed your code; the output (as you have been told) looks correct to me.

I suggest you don't put your Java work on your desktop. Next time you open a command prompt, give it the following instructions:

mkdir java
cd java

You now have a "java" directory (you can call it anything you like) which will be inside "My Documents" and you can get there easily by typing

cd java

and you can keep all your work there
 
Tariq Ab
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to JavaRanch

Please use the CODE button; since you are new I have gone back to your post and edited it, so you can see how much better it looks. Please use copy-and-paste rather than a screenshot to show your output. Click the icon on the top left of the command prompt window, then edit, then mark, then use mouse to highlight, then enter key.

I couldn't read the full output, so I copied and executed your code; the output (as you have been told) looks correct to me.

I suggest you don't put your Java work on your desktop. Next time you open a command prompt, give it the following instructions:

mkdir java
cd java

You now have a "java" directory (you can call it anything you like) which will be inside "My Documents" and you can get there easily by typing

cd java

and you can keep all your work there



That looks much better, thank you!

the code runs fine and everything, but the beginning of the output is what i'm getting wrong.

Instead of getting :

99 BOTTLES OF BEER ON THE WALL
99 BOTTLES OF BEER
etc....

I'm getting the output starting from number 60?!!! and the order of the lyrics is kinda messed up at the beginning of the output:

60 bottles of beer
Take one down.
Pass it around.
59 bottles of beer on the wall
59 bottles of beer on the wall
59 bottles of beer
Take one down.
Pass it around.
58 bottles of beer on the wall
58 bottles of beer on the wall
58 bottles of beer
Take one down.
Pass it around.






I hope my way of asking questions is better now,

thank you,
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're seeing the tail end of the output. If, theoretically, you could scroll up, you'd see the rest... but it looks like your command window isn't letting you.

Try using System.out.print() instead of System.out.println()

You'll see all the output crushed together in a huge (ugly) paragraph.

Let me know how that works out.
Janeice

 
Tariq Ab
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's weird, it worked! but as you said its all crushed together.

thank you so much!
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YAY!!!

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic