Assignment #61

Code

    ///jack newsom
///period 2
///program KeepGuessing
///filename KeepGuessing.java
///date completed 10/7/15

import java.util.Scanner;

import java.util.Random;

public class KeepGuessing
{
    public static void main( String[] args )
    {
        Scanner numbot = new Scanner(System.in);
        Random r = new Random();
        
        System.out.println("I have randomly chosen a number between 1 and 10. Try to guess it!");
        int guess = numbot.nextInt();
        
        int actual = 1 + r.nextInt(10);
        
        while ( guess != actual )
        {
            System.out.println("That's incorrect. Try again.");
            System.out.print("Your guess: ");
            guess = numbot.nextInt();
        }
        
        System.out.println("That's right! You're a good guesser.");
    }
}
    

Picture of the output

Assignment X