Assignment #72

Code

    ///Name: Cody Swain
    ///Period: 6
    ///Project Name: DiceDoubles
    ///File Name: DiceDoubles.java
    ///Date: 12/7/15
    
    import java.util.Random;
    import java.util.Scanner;
        
    public class NumberGuessingAgain
    {
        public static void main( String[] args )
        {
            
        Random r = new Random();
        Scanner keyboard = new Scanner(System.in);
        int secretNumber = 1 + r.nextInt(10);
        int guess, tries = 0;
        
        System.out.println("I'm thinking of a number between 1-10. Try to guess it. ");
        System.out.println();
        
        do
        {
            System.out.print("Your guess: ");
            guess = keyboard.nextInt();
            if ( guess != secretNumber ) {
            System.out.println( "That is incorrect. Guess again. " );
            }
            tries++;
        } while ( guess != secretNumber );
            
        System.out.println("That's correct, my secret number was " + secretNumber );
        System.out.println("You guessed " + tries + " times. " );
        }
    }
                
                
        
    

Picture of the output

Assignment 72