How to match the given output for Java Computer Guess Your Number Game; Binary Search
<p>I have been having a lot of trouble with this and it is due soon, and I was wondering if anyone knows how to fix my problem. I have to create a program where: 
"Your task is to implement a number guesser that works on the principle of a binary search. In each step, the computer cuts the query interval in half. When the interval contains a single number, it proclaims the answer. The user of the program selects a number between 1 and 100. The computer is then asked to guess the number."</p>

<p>The sample output goes:</p>

<pre class="lang-none prettyprint-override"><code>Is your number greater than 50? (computer is asking this)
no (user responds with yes or no)
Is your number greater than 25?
no
Is your number greater than 13?
no
Is your number greater than 7?
yes
Is your number greater than 10?
yes
Is your number greater than 12?
yes
Is your number 13?
yes
13 is the answer. (computer declares final answer)
Thank you for playing the guessing game.
</code></pre>

<p>My sample output in contrast goes:</p>

<pre class="lang-none prettyprint-override"><code>Is your number greater than 50?
no
Is your number greater than 25?
no
Is your number greater than 13?
no
Is your number greater than 7?
yes
Is your number greater than 10?
yes
Is your number greater than 11?
yes
Is your number greater than 12?
yes
Is your number 12?
yes
12 is the answer.
Thank you for playing the guessing game.
</code></pre>

<p>with some variation based on what edits I make.</p>

<p>The code is as follows:</p>

<pre><code>//import statements
import java.util.Scanner;
import java.util.ArrayList;
public class Numbers
{


//constant to initialize the ArrayList
private final int AT_MOST = 100;
//anArrayList of type ArrayList&lt;Integer&gt; which is to hold the values from 1 - 100 
private ArrayList&lt;Integer&gt; anArrayList;


/**
 * Constructor of the Numbers() class which initializes all of the instance fields
 */
public Numbers()
{
    anArrayList = new ArrayList&lt;Integer&gt;();
    int i =0;
    //while loop to initialize anArrayList with values from 1-100
    while(i &lt; AT_MOST)
    {
        anArrayList.add(i+1);
        i++;
    }
}

public void search()
{
    int low = 0;
    int high = anArrayList.size();
    int i = 0;
    int j = 0;
    while(low &lt;= high)
    {
        int mid = (low + high)/2;
        mid = anArrayList.get(mid - 1);
        Scanner in = new Scanner(System.in);
        System.out.println("Is your number greater than " + mid + "?");
        String answer = in.nextLine();
        if(answer.equalsIgnoreCase("yes"))
        {

            low = mid + 1;

        }
        else if (answer.equalsIgnoreCase("no"))
        {

            high = mid - 1;
            low++;
        }
        if(low == high+1)
        {
            Scanner in2 = new Scanner(System.in);
            System.out.println("Is your number " + mid + "?");
            String finalAnswer = in2.nextLine();
            if(finalAnswer.equalsIgnoreCase("yes"))
            {
                System.out.println(mid + " is the answer.");
                System.out.println("Thank you for playing the guessing game.");
                low = high + 1;;
            }
            else
            {
                System.out.println("Please play again, something went wrong!");
                low = high + 1;
            }
        }
    }
}
}
</code></pre>

<p>Of course this also has a tester class which is relatively short:</p>

<pre><code> public class NumbersGuesser
 {
  public static void main(String[] args)
   {
    //creates a new numbers object
    Numbers newNumber = new Numbers();
    //run method is called, game is played.
    newNumber.search();
    }
}
</code></pre>
