I have a random number guesser and I am trying to figure out how to get it to print and follow the other directions. Can someone help?
The instructions:
- Choose a random number from 0-100
- Get the first guess
- Loop while the guess does not equal the random number,
- If the guess is less than the random number, print out “Too low!”
- If the guess is greater than the random number, print out “Too high!”
- Get a new guess (save it into the same variable)
- Print out something like “You got it!”
My code so far:
Scanner user = new Scanner(System.in);
int randoNum = 1 + (int) (Math.random()* 99);
int guess;
System.out.println("Guess a number from 0 to 100");
guess = user.nextInt();
while (guess != randoNum);
{
if (guess < randoNum)
{
System.out.println("Too low!");
}
else if (guess > randoNum)
{
System.out.println("Too high");
}
else
{
System.out.println("You got it!");
}
}
Aucun commentaire:
Enregistrer un commentaire