what's the issue here?

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());
int max = 0;
int res = 0, neg = -1;
while(n > 0) {
int a = Integer.parseInt(reader.readLine());
if( a < 0 ) {
if(a > neg) neg = a;
}
if(a > res ) {
res = a;
}
n--;
}
if(res > 0) System.out.println(res);
else System.out.println(neg);
}
}

resequals 0 then outputneg. Fix this and your code will pass.