import java.io.*; public class NumberGuess { public static void main(String[] args) throws IOException { int guess; // human guess of target int count; // # guesses to reach target final int LOW=Integer.parseInt(args[0]); // lowest value of target final int HIGH=Integer.parseInt(args[1]); // highest value of target final int STOP=HIGH-LOW+1; // maximum number of guesses int target = (int) (Math.random()*(HIGH-LOW+1)) + (int) (LOW); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nGuess an integer: "); guess = Integer.parseInt(in.readLine()); count = 1; while ( guess != target && guess >= LOW && guess <= HIGH && count < STOP ) { if (guess < target) System.out.println("Too low!"); else if (guess > target) System.out.println("Too high!"); else System.exit(0); System.out.print("\nGuess an integer: "); guess = Integer.parseInt(in.readLine()); count++ ; } if (target == guess) System.out.println("\nCongratulations!\n"); } }