I am attempting to write basic code for a binary search. Here is the code I have:
public class BinarySearch { public static final int NOT_FOUND = -1; public static int binarysearch(int [] a, int x) { int low = 0; int high = a.length - 1; int mid; while(low<=high) { mid = (low + high) / 2; if(a[mid].compareTo(x) < 0) low = mid + 1; else if(a[mid].compareTo(x) > 0) high = mid - 1; else return mid; } return NOT_FOUND; } public static void main(String [] args) { int SIZE = 6; int [] a = new Integer[SIZE] = {-3, 5, 10, 10.5, 24, 45.3}; System.out.println("45.3 found at " + binarysearch(a,45.3)); } }
However, when I attempt to compile, I am given a message that says this line of code:
has an "illegal start of expression". I don't know what this means much less how to fix it.int [] a = new Integer[SIZE] = {-3, 5, 10, 10.5, 24, 45.3};
Help would be much appreciated. Thank You!