Hello everyone,
I am not sure why my solution doesn´t meet the requirements since it produces the desired output (at least from what i tested).
Thanks for any help in advance.
package de.codegym.task.task10.task1019;
import java.io.*;
import java.util.HashMap;
/*
Funktionalität ist nicht genug!
*/
public class Solution {
public static void main(String[] args) throws IOException {
//BufferedReader to read new Strings
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, Integer> map = new HashMap<String, Integer>();
while(true) {
//Read String for the receiving the number
String s = reader.readLine();
//If String is empty, then breal the while loop because no number input occured
if(s==null) {
break;
}
//Parse String to int and read the name
int id = Integer.parseInt(s);
String name = reader.readLine();
//Even if the name is empty, save its value in the hashmap
if(name==null) {
name = "";
}
//Put name as key (because name is defined as individual) and id as value (because id is defined to vary)
map.put(name, id);
}
//Show the content of the hashmap as defined in the task
for (HashMap.Entry<String, Integer> paar : map.entrySet()) {
System.out.println(paar.getValue() + " " + paar.getKey());
}
}
}