wood burning stoves*
The moose likes Beginning Java and the fly likes 99 bottles of beer song....... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "99 bottles of beer song......." Watch "99 bottles of beer song......." New topic
Author

99 bottles of beer song.......

James Swanson
Greenhorn

Joined: Oct 17, 2004
Posts: 9
ok i have just started learning java and i have to make a loop to make the song "play through" so to speak

hear is what I have so far

its not doing what want it to, but it is doing what i told it too lol

can anybody please help?

thank you

public class ninetyninebottlesofbeer {

static int count = 99;
static int range = 1;
static int beer = count - range;



public static void main(String [] Args) {



beer = count - range;

while (count >= 1);{

System.out.println (+ count + "Bottles of beer on the wall" + count + "bottles of beer!");
System.out.println ("you take one down and pass it around" + range + "bottles of beer on the wall");

count++;

}

}
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
looks like this
count++;

s/be
count--;

Shoulda tested before posting!!

this line seems to be the problem (the semi-colon
while (count >= 1);{
[ October 17, 2004: Message edited by: Michael Dunn ]
James Swanson
Greenhorn

Joined: Oct 17, 2004
Posts: 9
awsome thak you sooo much!!!

that seemed too easy for me to miss- lol

although i can't get any spaces between my ints and characters

can ya tell me about that?

heres what it looks like now

//
//James Swanson
//ssd-101 intro to Java
//prof. Hufe
//mondays 530
//
//
//99 bottles of beer on the wall
//



public class ninetyninebottlesofbeer {

static int count = 99;
static int range = count - 1;




public static void main(String [] Args) {




while (count >= 1) {

System.out.println (+ count + "Bottles of beer on the wall" + count + "bottles of beer!");
System.out.println ("you take one down and pass it around" + range + "bottles of beer on the wall");
count--;
range--;

}

}
}

also if you know of any other site that can help(not that I don't love this place enough) that would be a great help too

thank you so much again
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Just include the spaces in the string part of your System.out.println();
ie "Bottles of beer on the wall"
becomes " Bottles of beer on the wall "

another good place for java
Sun Java Forums
James Swanson
Greenhorn

Joined: Oct 17, 2004
Posts: 9
tahk you again you are the best!
James Swanson
Greenhorn

Joined: Oct 17, 2004
Posts: 9
um one more thing?

i am trying to make a nested if staement that will return to a scanner...

it looks like this ( ihave tested different ways and can't find my answer on the web)

System.out.print(guessMessage);
userNumber = scan.nextInt();
numberOfGuesses = 1;
if (userNumber < randomNumber)
System.out.print(tooLow);
else if (userNumber < randomNumber)
done = false;
else
done = true;

if (userNumber > randomNumber)
System.out.print(tooLow);;

else if (userNumber > randomNumber)
deon = false;
else
done = true;

what exactly am I doing wrong? it will print my message but not return..
i just stops if I reverse if and else if statements

thank you for any help
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
can you write out the text for those of us not from the US so we may be able to help?


42
James Swanson
Greenhorn

Joined: Oct 17, 2004
Posts: 9
sorry.....

import java.util.Random;
import java.util.Scanner;

public class HiLoGame{

public static void main(String[] args) {
boolean done = false;
boolean playAgain = true;
Random numberGenerator = new Random();
int randomNumber, numberOfGuesses, userNumber;
Scanner scan = new Scanner(System.in);


final String guessMessage = "Enter your guess (-1 to quit): ";
final String tooHigh = "Sorry, the number you entered is higher than my number.";
final String tooLow = "Sorry, the number you entered is lower than my number.";
final String justRight = "Congratulations! You guessed my number!";
final String playAgainMessage = "Play again?";

while (playAgain) {

randomNumber = numberGenerator.nextInt(10) + 1;


System.out.print(guessMessage);
userNumber = scan.nextInt();
numberOfGuesses = 1;
if (userNumber < randomNumber)
done = false;

else if (userNumber < randomNumber)
System.out.print(tooLow);
else
done = true;

if (userNumber > randomNumber)
done = false;

else if (userNumber > randomNumber)
System.out.print(tooHigh);
else
done = true;





while (userNumber < randomNumber)
done = false;

while (userNumber > randomNumber)
done = false;


while (userNumber == -1)
done = true;


while (userNumber == randomNumber)
done = true;



System.out.print("Would you like to play again? (y/n)? ");
if (scan.next().equals("n"))
playAgain = false;
else
done = false;
}

System.out.println("Thanks for playing! Bye!");

}

}

is that better
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Jeroen Wenting:
can you write out the text for those of us not from the US so we may be able to help?

99 bottles of beer on the wall, 99 bottles of beer,
If one of those bottles should happen to fall,
98 bottles of beer on the wall ........


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
James Swanson
Greenhorn

Joined: Oct 17, 2004
Posts: 9
so sorry..

it should say first

Enter your guess<-1 to quit>:

from there I would like it to say

Sorry, the number you entered is higher than my number.
--back to "Enter guess"
(or)

Sorry, but the number I entered is lower than my number
--back to "Enter guess"
(or)

Congratulations! You guessed my number!
--then to "play again?"

is that what you meant?

i works until the first number is higher or lower but I can't keep the loop going
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
generate the initial random number prior to the while loop,
which should be something like this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 99 bottles of beer song.......