I have this recommendation : "If an empty string is entered after a number, then that number should also be displayed (it must not be lost)." but when I'm testing this code on JVM everything working. When I write 1 a 2 3 c then I have 1 a 2 3 c.
package com.codegym.task.task10.task1019;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
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<Integer, String> a = new HashMap<>();
while(true) {
String x = reader.readLine();
if(x.equals("")){
break;
}
String y = reader.readLine();
a.put(Integer.parseInt(x), y);
}
Iterator<Map.Entry<Integer, String>> e = a.entrySet().iterator();
while(e.hasNext()){
HashMap.Entry<Integer, String> c = e.next();
System.out.println(c.getKey() + " " + c.getValue());
}
}
}