Error: "If an empty string is entered after a number, then that number should also be displayed (it must not be lost)."
HashMap can work with null key, no?
package com.codegym.task.task10.task1019;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
/*
Functionality is not enough!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, Integer> map = new HashMap<>();
while(true) {
int id = Integer.parseInt(reader.readLine());
String name = reader.readLine();
if(name.isEmpty()){
map.put(null, id);
break;
}else
map.put(name, id);
}
for(Map.Entry<String, Integer> pair : map.entrySet()){
String a = pair.getKey();
Integer b = pair.getValue();
System.out.println(a+ " " +b);
}
}
}