// This program plays a simple guessing game with the user. // (Version of the handout as we developed it in class) import java.util.*; public class SimpleGuess { public static void main(String[] args) { Scanner console = new Scanner(System.in); giveIntro(); Random r = new Random(); // returns 0-9 int target = r.nextInt(10) + 1; // System.out.println(target); // Priming the loop int guess = -1; int count = 0; while (guess != target) { System.out.print("Guess: "); guess = console.nextInt(); count = count + 1; } System.out.println("You got it right in " + count + " guess(es)"); } // explains the program to the user public static void giveIntro() { System.out.println("This program plays a guessing game with you."); System.out.println("I'm thinking of a number between 1 and 10."); System.out.println(); } }