It says:
recommendation from your mentor
Bear in mind that numbers can be negative.
But when I test it in IntellIJ IDEA with a file, it gives correct output for negative numbers as well.
Input used:
1
2
3
4
5
6
-4
-4
7
7
-2
-7
-1
-46
Output given:
2
4
6
-4
-4
-2
-46
package com.codegym.task.task13.task1326;
/*
Sorting even numbers from a file
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Solution
{
public static void main(String[] args) throws IOException
{
BufferedReader keyboardReader = new BufferedReader(new InputStreamReader(System.in));
FileInputStream fileInput = new FileInputStream(keyboardReader.readLine());
Scanner fileScanner = new Scanner(fileInput);
keyboardReader.close();
ArrayList<Integer> input = new ArrayList<>();
while (fileScanner.hasNextInt())
{
int nextInt = fileScanner.nextInt();
if (nextInt % 2 == 0)
input.add(nextInt);
}
fileInput.close();
input.forEach(System.out::println);
}
}