Assignemnt #72: Using Do While Loops while Guessing a Number

Code

     /// Name: Sean Harrison
    /// Period: 7
    /// Program name: DoWhileGuess
    /// File Name: DoWhileGuess.java
    /// Date Finished: 1/5/2016
    
import java.util.Random;
import java.util.Scanner;
public class DoWhileGuess
{
    public static void main( String[] args )
    {
    Random r = new Random();
    Scanner keyboard = new Scanner(System.in);
    int randomNumber, guess, tries;
    tries = 0;
    randomNumber = 1 + r.nextInt(10);
    System.out.println( " I have choosen a random number from 1 through 10, you will attempt to guess it until you are correct. " );
    guess = keyboard.nextInt();
    tries++;
        do 
        {
            System.out.println( " You are incorrect please try again. " );
            guess = keyboard.nextInt();
            tries++;
        }
            while ( guess != randomNumber );
            System.out.println( " Nice job, you picked the correct number. " );
            System.out.println( " It took you " + tries + " tries. " );
        }
    }
                
        
          
 

Picture of the output

Assignment 72