Assignemnt #72: Again with the Number-Guessing Game

Code

    /// Name: Cassie
    /// Period: 6
    /// Program Name: Again with the Number-Guessing Game
    /// File Name: guessagain.java
    /// Date Finished: 1/14/2016
    
    import java.util.Random;
    import java.util.Scanner;
    class guessagain
    {
    	public static void main ( String[] args )
    	{
    		Random r = new Random();
            Scanner keyboard = new Scanner(System.in);
            int guess, guesses=0, ans = 1 + r.nextInt(10);
            System.out.print( "Please guess a number between 1-10      " );
            guess = keyboard.nextInt();
            
            do
            {
                if ( guess != ans )
                {
                    System.out.print( "\nincorrect! guess again!    " );
                    guesses++;
                    guess = keyboard.nextInt();
                }
            } while ( guess != ans );
            
            if ( guesses > 0)
            {
                guesses++;
    			System.out.println( "That's right! You're a good guesser. It only took you  " + guesses + " tries " );
            }
            else 
            {
                guesses++;
                System.out.println( "Wow thats right in 1 guess. You're a good guesser!" );
            }
        }
    }
    

Picture of the output

Assignment 72