I'm not sure what I'm missing here. It says "Be sure that the program works correctly for negative numbers." It seems to, unless I'm not understanding it correctly.
If I enter a number less than 0 for the first number, it ends.
if I enter negative numbers for the second part, then they don't display, because they are less than 0 (or other highest entered number).
I'm guessing it doesn't like my int maximum being initialized at 0, but if I don't initialize it I can't test against it.
I tried setting an if statement, testing against a boolean so the first time I entered a number (after the first N) it would set maximum to that, so it could be set to negative numbers too..but that didn't pass this requirement either.
Any hints? Thanks.
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;
int count;
boolean first = true;
int n = Integer.parseInt(reader.readLine());
if (n > 0) {
for (count = 0; count < n; count++) {
int a = Integer.parseInt(reader.readLine());
if (first) {
maximum = a;
first = false;
}
maximum = (a > maximum ? a : maximum);
}
}else;
if (maximum <= 0)
;
else
System.out.println(maximum);
}
}