Why my code doesn't pass a next-to-last test? "The program should display the maximum of the N entered numbers."
package com.codegym.task.task05.task0532;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> lista = new ArrayList<>();
while (true) {
try {
int maximum = Integer.parseInt(reader.readLine());
if (maximum == 0 || maximum < 0) {
break;
} else
lista.add(maximum);
if (lista.contains(null) || lista.contains(" "))
break;
} catch (Exception e) {
System.out.println(Collections.max(lista));
break;
}
}
}
}