The code works, but fails the tasks... Why?
package com.codegym.task.task05.task0532;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import static java.lang.Integer.MIN_VALUE;
/*
Write a program that:
1. reads a number N (must be greater than 0) from the console
2. reads N numbers from the console
3. Displays the maximum of the N entered numbers.
Requirements:
1. The program should read the numbers from the keyboard.
2. The program must display a number on the screen.
3. The class must have a public static void main method.
4. Don't add new methods to the Solution class.
5. The program should display the maximum of the N entered numbers.
6. The program should not display anything if N is less than or equal to 0.
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> list = new ArrayList<>();
while(true){
String sNum = reader.readLine();
if(sNum.isEmpty()) {
break;
}else{
int N = Integer.parseInt(sNum);
if(N <= 0) {
break;
}else{
list.add(N);
}
}
}
int maximum = MIN_VALUE;
for(int i = 0;i < list.size();i++) {
if (list.get(i) > maximum) {
maximum = list.get(i);
}
}
if(maximum > 0) System.out.println(maximum);
}
}