Assignment #61

Code

    /// Name: Jonathan Stine
    /// Period: 5
    /// Program Name: Keep Guessing
    /// File Name: KeepGuessing.java
    /// Date Finished: 1/19/16
    
    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. If you guess it nothing happens. Happy now?" );
            System.out.print( "Your guess: " );
            guess = keyboard.nextInt();
            
            while ( guess != number ) {
                System.out.println( "That's incorrect. Guess again." );
                System.out.print( "Your guess: " );
                guess = keyboard.nextInt();
            }
            
            System.out.println( "That's right! Give yourself a pat on the back." );
        
        }
    }
    
 
    

Code Output