The mentor recommendation is: If an empty string is entered after a number, then that number should also be displayed (it must not be lost).
Except it is currently doing that.
I entered:
1
a
2
b
3
c
4
And the output was:
1 a
2 b
3 c
4
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 {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<Integer, String> map = new HashMap<>();
while(true) {
String s = reader.readLine();
if(s.equals("")) { //or s.isEmpty()
break;
}
int id = Integer.parseInt(s);
String name = reader.readLine();
if (name.equals("")){//or name.isEmpty()
map.put(id, "");
break;
}
map.put(id,name);
}
for (HashMap.Entry<Integer, String> pair : map.entrySet()){
Integer key = pair.getKey();
String value = pair.getValue();
System.out.println(key + " " + value);
}
}
}