/* EXPECTED OUTPUT: This program has you, the user, choose a number between 1 and 10, then I, the computer, will try my best to guess it. Is it 8? (y/n) n Is it 7? (y/n) n Is it 5? (y/n) n Is it 1? (y/n) n Is it 8? (y/n) n Is it 1? (y/n) n Is it 9? (y/n) y I got your number of 9 correct in 7 guesses. */ import java.util.*; // Asks the user to do multiplication problems and scores them. public class NumberGuess { public static final int MAX = 10; public static void main(String[] args) { printWelcomeMessage(); Scanner console = new Scanner(System.in); /* A loop-and-a-half / fencepost problem. We'll do one guess first outside the loop, then continue looping as long as our guess wasn't correct. */ Random randy = new Random(); int guess; int numGuesses = 0; String response; do { // do another guess and ask whether it was correct guess = randy.nextInt(MAX) + 1; System.out.print("Is it " + guess + "? "); response = console.next(); numGuesses++; } while (response.equals("n")); // print results System.out.println(); System.out.println("I got your number of " + guess + " in " + numGuesses + " guesses."); } // Prints a welcome message to the user. public static void printWelcomeMessage() { System.out.println("This program has you, the user, choose a number"); System.out.println("between 1 and " + MAX + ", then I, the computer, will try"); System.out.println("my best to guess it."); System.out.println(); } }