import java.util.Scanner;

public class HW2 {
    public static void main(String[] args) {
        int lowRange = 0, highRange = 100, UserGuess, UserInput;
        boolean CorrectGuess = false;
        int attempts = 0;

        Scanner input = new Scanner(System.in);

        System.out.println("Think a number between 0 and 100.");

        int[] list = new int[101];
        for (int i = 0; i <= 100; i++)
            list[i] = i;

        while(!CorrectGuess) {
            int midRange = lowRange + (highRange - lowRange) / 2;

            UserGuess = list[midRange];
            attempts++;

            System.out.println("Is " + UserGuess + " the number?");
            System.out.println("Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:");

            UserInput = input.nextInt();

            if (UserInput == 1) {
                CorrectGuess = true;
                System.out.println("Computer spent " + attempts + " tries to guees your number!");
            } else if (UserInput == 2)
                lowRange = midRange;
            else if (UserInput == 3)
                highRange = midRange;
        }
    }
}