aspose file tools*
The moose likes Beginning Java and the fly likes BeerSong Java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BeerSong Java code" Watch "BeerSong Java code" New topic
Author

BeerSong Java code

Tariq Ab
Greenhorn

Joined: Oct 24, 2009
Posts: 14
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


[Thumbnail for Output.jpg]

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1732
    
  12

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


When you do things right, people won't be sure you've done anything at all.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
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

Joined: Oct 24, 2009
Posts: 14
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

Joined: Sep 14, 2009
Posts: 1732
    
  12

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

Joined: Oct 24, 2009
Posts: 14
that's weird, it worked! but as you said its all crushed together.

thank you so much!
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1732
    
  12

YAY!!!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BeerSong Java code