Codegym is recommending this
If an empty string is entered after a number, then that number should also be displayed (it must not be lost).
How to do that.
package com.codegym.task.task10.task1019;
import java.io.*;
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){
String s = reader.readLine();
if (s.equals("")){
break;
}
int id = Integer.parseInt(s);
String name = reader.readLine();
if (name.equals("")){
break;
}
map.put(name,id);
}
for (Map.Entry<String, Integer> pair : map.entrySet()){
String s = pair.getKey();
int i = pair.getValue();
System.out.println(i + " " + s);
}
}
}