My output is:
Input
1
Sam
2
I
1
Am
Out Put
2 I
1 Am
1 Sam
Process finished with exit code 0
Please note in my code I have enabled System.out.println("Id=" + pair.getValue() + "Name=" + pair.getKey()); for testing purposes.
package com.codegym.task.task10.task1019;
import java.io.*;
import java.util.HashMap;
/*
Functionality is not enough!
*/
public class Solution {
public static void main(String[] args) throws IOException {
HashMap<String,Integer> map = new HashMap<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String x = reader.readLine();
if(x.isEmpty()) break;
int id = Integer.parseInt(x);
String name = reader.readLine();
if(name.isEmpty()){
map.put("No Name",id);
break;
}
map.put(name, id);
}
for (HashMap.Entry<String, Integer> pair : map.entrySet()) {
//System.out.println(pair.getValue() + " "+ pair.getKey());
System.out.println("Id=" + pair.getValue() + "Name=" + pair.getKey());
}
}
}