Ok so I'm trying to find the largest element in an array, and I realize this is not the best method to do this, it only works in some cases. Would appreciate some pointers on how to change my code so it works for all instances.
public static int maxArray(int[] a) {
int max = 0;
for (int j = 0; j < a.length-1; j++) {
if (a[j+1] > a[j]) {
max = a[j+1];
} else {
max = a[j];
}
}
return max;
}