This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tahk you again you are the best!
 
James Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you write out the text for those of us not from the US so we may be able to help?
 
James Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ........
 
James Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generate the initial random number prior to the while loop,
which should be something like this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic