/** * Guessing game: TooLargeTooSmall. * * @author (Chistian) * @version (version1 10-19-18) */ import java.util.*; import java.util.Scanner; public class Main { public static void main(String[] args){ Random rand = new Random(); int n = rand.nextInt(10) + 1; Scanner in = new Scanner(System.in); System.out.println("Please guess a number between 1 and 10"); int guess = in.nextInt(); int lastGuess = 0; int numberOfGuesses=1; while (n != guess){ if (n < guess) { System.out.println("too large, guess another number"); if (guess != lastGuess){ lastGuess = guess; numberOfGuesses++;} } else if(n > guess) { System.out.println("too small, guess another number"); if (guess != lastGuess){ lastGuess = guess; numberOfGuesses++;} } guess = in.nextInt(); } System.out.println("correct! you took " +String.format("%d",numberOfGuesses)+ " guesses to get it right"); } }