This code doesn't pass and displays following message Be sure that the max method works correctly with negative numbers.
public class Solution {
public static void main(String[] args) throws Exception {
int[] array = initializeArray();
int max = max(array);
System.out.println(max);
}
public static int[] initializeArray() throws IOException {
// Create and populate the array
int[] arr = new int[20];
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
arr[i] = scanner.nextInt();
}
return arr;
}
public static int max(int[] array) {
// Find the maximum
int max = 0;
for (int value : array) {
if (value > max) {
max = value;
}
}
return max;
}
}