Hey guys,
maybe I'm blind or sth but i cant see whats wrong with it. It seems to work with negative numbers though.
package com.codegym.task.task07.task0701;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
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 {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] array = new int[20];
for (int i = 0; i < array.length; i++) {
array[i] = Integer.parseInt(reader.readLine());
}
return array;
}
private static int max(int[] array) {
int max = array[0];
for (int i = 0; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
}