Assignment #61 Keep Guessing
Code
/// Name: Matthew Lorence
/// Period: 5
/// Program Name: Guessing Game
/// File Name: GuessingGame.java
import java.util.Scanner;
import java.util.Random;
public class GuessingGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int number = 1 + r.nextInt(10);
System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
System.out.print("Your guess: ");
int guess = keyboard.nextInt();
while ( guess != number )
{
System.out.println("That is incorrect. Guess again. ");
System.out.print("Your guess: ");
guess = keyboard.nextInt();
}
System.out.println("That's right! You're a good guesser.");
}
}
Picture of the output