Binary searching in an array <p>This code searches for a number in an array by using the median. I have a problem with printing its position in the array. This code prints out the max value of the array. ex "234" "your number is on the the place 99999" "345" "your number is on the place 99998" and so on.</p> <pre><code>import java.util.Scanner; import java.util.Arrays; public class sok2 { public static void main(String[] args) { int ListaLength = 100001; //Säger hur lång listan ska vara. int [] array = new int[ListaLength]; for (int i = 0; i &lt; ListaLength; i++) { array[i] = (int)(Math.random() * ((ListaLength - 1) + 1)); Arrays.sort(array); System.out.println("Skriv in numret du letar efter."); int element = new Scanner(System.in).nextInt(); boolean found = false; int min = 0; int max = array.length - 1; int median = max/2; while(! found &amp;&amp; min &lt;= max){ if(array[median] == element){ found = true; } if(array[median] &lt; element){ min = median + 1; median = (min + max) / 2; } else if(array[median] &gt; element){ max = median - 1; median = (max + min) / 2; } } // this is where i assume the problem is. System.out.println("Din siffra är på plats "+median); }}} </code></pre>