I'm trying to run this code that returns the maximum value in the given array. I'm brand new to Java so I would greatly appreciate any debugging tips.
public class maxVal { public static int max(int[] m) { int maxSoFar=m[0],i; for (i=1; i<m.length;i++) { if (m[i]>maxSoFar) maxSoFar=m[i]; } return maxSoFar; } public static void main(String[] args) { int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6}; max(numbers); } }
maxmethod returns a value so you may want to print it out.