Что не так с моим выводом? Не могу понять суть ошибки :d
package com.javarush.task.task10.task1019;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
/*
Функциональности маловато!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<Integer, String> map = new HashMap<>();
ArrayList<Integer> ar1 = new ArrayList<>();
ArrayList<String> ar2 = new ArrayList<>();
while (true) {
String s = reader.readLine();;
if (s == null || s.isEmpty()) {
break;
}
Integer x = Integer.parseInt(s);
String y = reader.readLine();
if (y == null || y.isEmpty()) {
break;
}
if (map.containsKey(x)) {
ar1.add(x);
ar2.add(y);
map.put(null, null);
} else {
map.put(x, y);
}
}
for (Map.Entry<Integer, String> pair : map.entrySet()) {
Integer a = pair.getKey();
String b = pair.getValue();
if (a != null) {
System.out.println(a + " " + b);
} else {
for (int j = 0; j < ar1.size(); j++) {
System.out.println(ar1.get(j) + " " + ar2.get(j));
}
}
}
}
}