First of all I need a calculation for when the looked for number is greater then the number "landed" on. (less and I can just use /2 but I don't know what to do when it's the other way since I use int and not double.)
Secondly I'm getting an out of bounds error which I don't know the cause of.
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JOptionPane;
public class BinärSökning {
public static void main(String[] args){
ArrayList<Integer> listA = new ArrayList<Integer>();
Integer[] otherList = new Integer[] {1,2,3,4,5,6,7,8,9,10};
listA.addAll(Arrays.asList(otherList));
String lts = JOptionPane.showInputDialog("Which number between 1 and 10 are you looking for? ");
int lt = Integer.parseInt(lts);
int s = listA.size()/2;
while(true){
if(lt==listA.get(s)){
System.out.println("Number found in position " + s);
}if(lt<listA.get(s)){
s = ???;
}else{
s = s/2;
}
}
}
}