statements will not be displayed.
**/
/*This is a game in which the user guesses
which number the random number generator created.
**/
import java.util.Random;
import java.util.Scanner;
class ch4no17
{
public static void main(String[] args) {
Random ranNum = new Random();// random number
int number;
int numInput = 0;
number = ranNum.nextInt(25);//guess between 0-25
Scanner numIn = new Scanner(System.in);//allows user to input number
numInput = numIn.nextInt();//sets user input equal to number
System.out.println(numIn.nextLine());//displays user input
//pre-test loop which tests to see if user has guess the
//randomly generated number correctly
while (numInput != number)
{
numInput = numIn.nextInt();
}
if (numInput == number)
System.out.println("Congratulations! You got it right!");
else if (numInput < number)
System.out.println("Too low, try again");
else if (numInput > number)
System.out.println("Too high, try again");
}
}

New Topic/Question
Reply



MultiQuote





|