Assignemnt #57 keep Guessing
Code
///Name:JJ Deng
///Period:6
///Program Name: Keep Guessing
///File Name: KeepGuessing.java
///Date Finished: 12/14/15
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.Random;
public class KeepGuessing
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int SecretNumber = 1 + r.nextInt(10);
int guess = 0;
System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
System.out.println();
System.out.print("Your guess: ");
guess = keyboard.nextInt();
while (guess != SecretNumber)
{
System.out.println("That is incorrect. Guess again.");
SecretNumber = keyboard.nextInt();
}
System.out.println(" That is right! You're a good guesser!" );
}
}
Picture of the output