Assignemnt #72 and Shorter Number Guessing game with a counter

Code


///Name: Ben Borglin
///Period: 6
///Program name: Short Count Number
///file name: ShortCountNumber.java
///Date Finsihed: 10/23/15

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

public class ShortCountNumber
{
    public static void main ( String[] args )
    {
        Scanner keyboard = new Scanner(System.in);
        Random r = new Random();
        int choice, x;
        int tries = 0;
        
        System.out.println("Im thinking of a number between 1 to 10.");
        do
        {
            x = 1 + r.nextInt(10);
            System.out.print("Your Guess: ");
            choice = keyboard.nextInt();
            System.out.println("Sorry that was incorrect ... Try again.");
            tries++;
        }while ( choice != x );
        
        
        System.out.println("\nYou're right! Nice guess.");
        System.out.println("It took you " + tries + " tries.");
        
            
     }
}
    

Picture of the output

Assignment 65