Проверял по всякому.
package com.javarush.task.task05.task0532;
/*
Задача по алгоритмам
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int maximum = 0;
int N = Integer.parseInt(reader.readLine());
if (N <= 0)
return;
int counter = 0;
int previous = 0;
int next = 0;
while (counter < N) {
next = Integer.parseInt(reader.readLine());
counter++;
if (counter == N) {
if (next > previous)
maximum = next;
else
maximum = previous;
}
previous = next;
}
System.out.println(maximum);
}
}