Assignment 65
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, guess;
answer = 1 + r.nextInt(10);
guess = 0;
int tries = 1;
System.out.print("I'm thinking of a number from 1 to 10.\nYour guess: ");
guess = keyboard.nextInt();
while (guess != answer)
{
System.out.print("That is incorrect. Guess again.\nYour guess: ");
guess = keyboard.nextInt();
tries ++;
}
System.out.println("That's right! My secret number was " +guess+ "!\nIt took you " +tries+ " tries.");
}
}