I am recently finished creating a program that checks if a user-inputted int array is arranged in ascending order. I have my function isAsc here:
public static boolean isAsc(int[] arr, int index){
if (index==1 || arr.length==1){
return true; //Base case
}
else if (arr[index-2] >= arr[index-1]){
return false;
}
else
return isAsc(arr, index-1); //recursive step
}
And the logic seems to be correct. However, what I don't get is when I call the function: System.out.print(isAsc(arr, arrayLength-1));
the output is wrong. This System.out.print(isAsc(arr, arrayLength));
yields the correct answer. Why? Thanks!
>=to>.