I get the output 13, 13, 45 for the input suggested in the exercise. What am I doing wrong? I feel it's from the fileinputstream but I can't put my finger on it. Please advise.
This is the current form, I don't know why it isn't updated.
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileInputStream input = new FileInputStream(reader.readLine());
ArrayList<Integer> nrs = new ArrayList<>();
int i = 0;
while ((i = input.read()) != -1) {
if (input.read() % 2 == 0)
nrs.add(input.read());
}
Collections.sort(nrs);
for (Integer f : nrs) System.out.println(f);
reader.close();
input.close();
}
}
package com.codegym.task.task13.task1326;
/*
Sorting even numbers from a file
*/
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileInputStream input = new FileInputStream(reader.readLine());
ArrayList<Integer> nrs = new ArrayList<>();
int i = 0;
while ((i = input.read()) != -1) {
nrs.add(input.read());
}
Collections.sort(nrs);
for (int j = 0; j < nrs.size(); j++) {
if (nrs.get(j) % 2 == 0) System.out.println(nrs.get(j));
}
reader.close();
input.close();
}
}