/** * Write a description of class GuessGame here. * * @author (your name) * @version (a version number or a date) */ import java.util.Random; import java.util.Scanner; public class GuessGame { // instance variables - replace the example below with your own private int x; /** * Constructor for objects of class GuessGame */ public static void main(String[] args){ System.out.println("Hello and welcome to my number guessing game."); System.out.println("Pick a number 1 through 10: "); Scanner input = new Scanner(System.in); int guess; int counter = 0; int prevGuess = -1; int rand = (int) (Math.random()*10)+1; boolean notCorrect = true; while(notCorrect){ guess = input.nextInt(); if(guess != prevGuess){ counter++; } prevGuess = guess; if(guess > rand){ System.out.println("Your guess is too high"); } else if(guess < rand){ System.out.println("Your guess is too low"); }else { notCorrect = false; System.out.println("You got it! " + counter + " guesses"); } } /*if (guess == number){ System.out.println("You got it!"); } else if (guess < number){ System.out.println("Your guess is too low"); } else if (guess > number){ System.out.println("Your guess is too high"); }*/ } }