As you can see, I have an if conditional on line 27 designed to guard against scenarios where n > 0. When I run the program with n values equal or less than 0, the program works as intended. Despite this, the checker doesn't seem to think so. What am I missing?
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 n = Integer.parseInt(reader.readLine()); //enter a number for n
long chall;
Maxnum maxnum = new Maxnum();
chall = Integer.parseInt(reader.readLine());
maxnum.setMax(chall);
for (int i = (n - 1); i > 0; i--)
{
chall = Integer.parseInt(reader.readLine());
maxnum.vsMax(chall);
}
long maximum;
maximum = maxnum.getMax();
if (n > 0)
{
System.out.println(maximum);
}
}
public static class Maxnum {
private long max;
public Maxnum()
{
}
public void setMax(long newMax)
{
max = newMax;
}
public long getMax()
{
return max;
}
public void vsMax(long challenger) {
if (max < challenger)
max = challenger;
else
max = max + 0;
}
}
}