import java.util.Random;
import java.util.Scanner;
/**
* Write a program where a random number is generated.
* Then the user tries to guess the number.
* If they guess too high display something to let them know,
* and same for if they guess a number that is too low.
* The loop must iterate until the number is guessed correctly.
*/
public class RandomGuess
{
public static int magicNumber;
public static int guess;
/*
*
*
*/
public static void main(String[] Args)
{
magicNumber = getRandomNumber();
Scanner scanner = new Scanner(System.in);
do
{
System.out.printf("Guess an integer between 0 and 100: ");
guess = scanner.nextInt();
if(guess < magicNumber)
{
System.out.printf("Higher!\n");
}
if(guess > magicNumber)
{
System.out.printf("Lower!\n");
}
}
while (guess != magicNumber);
if(guess == magicNumber)
{
System.out.printf("\nYou win! The number was %d.\n", magicNumber);
}
scanner.close();
}
/*
* @return the random number
*/
public static int getRandomNumber()
{
Random number = new Random();
int magicNumber = number.nextInt(0, 101);
return magicNumber;
}
}