I wrote this code, it works i think, but can't validate.
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 numberOfLines = Integer.parseInt(reader.readLine());
int helper = 0;
int maximum = 0;
int i = 0;
if (numberOfLines > 0) {
while (i < numberOfLines)
{
helper = Integer.parseInt(reader.readLine());
if (helper > maximum && -helper < maximum) // plus
{
maximum = helper;
}
if ((maximum > helper && (helper < 0) && (helper < -maximum))) // minus
{
maximum = helper;
}
i++;
}
}
System.out.println(maximum);
}
}
/* */
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 mennyi = Integer.parseInt(reader.readLine());
int seged = 0;
int maximum = 0;
int i = 0;
if (mennyi > 0) {
while (i < mennyi)
{
seged = Integer.parseInt(reader.readLine());
if (seged > maximum && -seged < maximum) // plus
{
maximum = seged;
}
if ((maximum > seged && (seged < 0) && (seged < -maximum))) // minus
{
maximum = seged;
}
i++;
}
}
System.out.println(maximum);
}
}
/* */