• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BeerSong Java code

 
Tariq Ab
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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]
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49823
69
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
that's weird, it worked! but as you said its all crushed together.

thank you so much!
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YAY!!!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic