I'm trying to call a method that prints the first and third quartiles of a data set (array of doubles), and to do that it needs to check whether or not the array of doubles has been sorted (using Array.sort() ). To check if the array has been sorted, I use static boolean isSorted(double data).
On the line containing the if-statement, I get the ArrayIndexOutOfBoundsException, when running the driver program. Any ideas as to how to fix this?
static boolean isSorted(double data)
int biggerCount = 0;
for(int m = 0; m<data.length;m++)
if(data[m] != Math.min(data[m], data[m+1]) )
if(biggerCount == 0)
problem has to be with the following part
if(data[m] != Math.min(data[m], data[m+1])
m+1 goes out of bounds. Look into it and make sure why you have to do m+1, if you must then you have check the array length so that it doesnt go beyond that such as
if((m+1)<data.length && data[m] != Math.min(data[m], data[m+1])
but u have to see what is your logic and why you are going beyond array limit
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)