Assignment 72
import java.util.Scanner;
import java.util.Random;
public class GuessingCounter
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int answer;
answer = 1 + r.nextInt(10);
int tries = 1;
System.out.print("I'm thinking of a number from 1 to 10.\nYour guess: ");
int guess = keyboard.nextInt();
do
{
System.out.print("That is incorrect. Guess again.\nYour guess: ");
guess = keyboard.nextInt();
tries ++;
} while (guess != answer);
System.out.println("That's right! My secret number was " +guess+ "!\nIt took you " +tries+ " tries.");
}
}