Assignment # 72 and Again with Number Guessing

Code

    /// Name: Tommy Oyuntseren
    /// Period: 7
    /// Program Name: AgainNumberGuessing
    /// File Name: AgainNumberGuessing.java
    /// Date: 1/14/2016

import java.util.Scanner;
import java.util.Random;

public class AgainNumberGuessing
{
    public static void main(String[] args)
    {
        Scanner keyboard=new Scanner(System.in);
        Random r= new Random();
        
        int x, guess;
        int tries=0;
        x = 1+r.nextInt(10);
        
        System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
        
        do
        {
            System.out.print("Your guess: ");
            guess = keyboard.nextInt();
            tries++;
            
            if (guess != x)
            {
                System.out.println("That is incorrect. Guess again.");
            }
        } while (guess != x);
            
            System.out.println("That's right! You're a good guesser.");
            System.out.println("It only took you " + tries + " tries.");
    }
}
   

  

Picture of the output

Assignment 72