Assignment #72

Code

    /// Name: Jonathan Stine
    /// Period: 5
    /// Program Name: Again with the Number-Guessing
    /// File Name: Again.java
    /// Date Finished: 1/19/16
    
    import java.util.Scanner;
    
    import java.util.Random;
            
    public class Again {
    
        public static void main( String[] args ) {
    
            Scanner keyboard = new Scanner(System.in);
    
            Random r = new Random();
    
            int guess, number, tries;
            number = 1 + r.nextInt(10);
    
            System.out.println( "I have chosen a number between 1 and 10. Type in what you think it is m80." );
            tries = 0;
    
            do {
                System.out.print( "Your guess: " );
                guess = keyboard.nextInt();
                tries++;
                
                if ( guess != number ) {
                    System.out.println( "That is incorrect. Guess again." );
                }
                
            } while ( guess != number );
    
            System.out.println( "That's right! You're a good guesser." );
            System.out.println( "It took you " + tries + " tries." );
    
        }
    }
    
    
 
    

Code Output