This method is working perfectly fine but I can't pass the validation (error occurs on step #3). Any suggestion where is the bug?
Thanks.
package com.codegym.task.task07.task0701;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Maximum in an array
*/
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
Scanner input = new Scanner(System.in);
int[] arr = new int[20];
for(int i = 0; i < arr.length; i ++){
arr[i] = input.nextInt();
}
return arr;
}
public static int max(int[] array) {
// Find the maximum
int max = array[0];
for(int i = 1; i < array.length; i++){
if(max <= Math.abs(array[i])){
max = Math.abs(array[i]);
}
}
return max;
}
}