So this class is supposed to print out the largest number in the array defined under the main method (aka 22) however when I run it nothing happens. I'm sure this is a very stupid question but today is my first day with java and I have already spent an embarrassing amount of time trying to figure it out. Thanks!
public class fun {
public static void main (String [] args) {
int[] numbers = new int[] {9, 2, 15, 2, 22, 10, 6};
max(numbers);
}
public static int max(int[] m) {
int length = m.length;
int counter = 1;
int currMax = m[0];
while (counter <= (length - 2)){
if (m[counter] > currMax){
currMax = m[counter];
}
counter = counter + 1;
}
return currMax;
}
}
maxmethod - you're stopping one number too soon, and effectively disregarding the last number on the list.currMaxism[0].