The code works. It prints out the correct answer, but clearly I am not doing it the right way or I have an error somewhere.
I am taking N from the keyboard and then loop N times. In this loop I set the highest nextN to int maximum. After loops are finished, I print out maximum. If N <= 0 I break the loop. So far the logic seems clear to me and I know I'm close, but can someone please help me finish this task correctly?
Thank you in advance.
package com.codegym.task.task05.task0532;
import java.io.*;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int maximum = 0;
//write your code here
int N = Integer.parseInt(reader.readLine());
for (int i = 0; i < N; i++) {
int nextN = Integer.parseInt(reader.readLine());
if (nextN > maximum) {
maximum = nextN;
}else if (N <= 0) {
break;
}
}System.out.println(maximum);
}
}