It's giving me output 5 when I enter 5,1,2,3,4,5 (where first 5 is the size)
Please help!

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 size = Integer.parseInt(reader.readLine()); //first enter the size in input
int[] num = new int[size]; //set array size equal to the size given in user-input.
int maximum = 0; //since it's a local variable, set it to some initial default value!
for(int i = 0; i < size; i++)
num[i] = Integer.parseInt(reader.readLine());
/* Enter all numbers one-by-one within declared user-input size.
This is important because when comparing num[i] with num[i+1] and user-input is taken
over there, then num[i] at that iteration is available for input, but next input isn'T
and it's required for further processing of that iteration. So separate loop for
input values is kept above
*/
/* To display all entered numbers in new line:
for(int i = 0; i < size; i++)
System.out.println(num[i]);
*/
for(int i = 0; i < size; i++) {
if(num[i] > 0) {
if(i == (size - 1))
maximum = num[i];
else if(num[i] > num[i+1])
maximum = num[i];
else
maximum = num[i+1];
}
}
//write your code here
System.out.println(maximum);
}
}