Assignment #61 Keep Guessing
Code
/// Name: Lacey Reese
/// Period: 5
/// Program Name: KeepGuessing
/// File Name: KeepGuessing.java
/// Date Finished 12/4/2015
import java.util.Scanner;
import java.util.Random;
public class KeepGuessing
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess, number;
number = 1 + r.nextInt(10);
System.out.println( "I have chosen a number between 1 and 10. Try to guess it! Good luck!!" );
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
while ( guess != number )
{
System.out.println( " Incorrect. Guess again!" );
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
}
System.out.println( "You got it right! CONGRATS! " );
}
}
Picture of the output
//