Assignemnt #65: Keep Guessing with a Counter

Code

 /// Name: Sean Harrison
    /// Period: 7
    /// Program name: KeepGuessingCounter
    /// File Name: KeepGuessingCounter.java
    /// Date Finished: 12/9/2015
    
    
import java.util.Random;
import java.util.Scanner;
public class KeepGuessingCounter
{
    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++;
    while ( guess != randomNumber )
        {
            System.out.println( " You are incorrect please try again. " );
            guess = keyboard.nextInt();
            tries++;
        }
            System.out.println( " Nice job, you picked the correct number. " );
            System.out.println( " It took you " + tries + " tries. " );
        }
    }

 

Picture of the output

Assignment 65