The output of my solution has a wrong order:
2 I
1 Am
1 Sam
How could i fix this. thank you
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 number = reader.readLine();
if (number.isEmpty()) break;
Integer id = Integer.parseInt(number);
String name = reader.readLine();
if (name.isEmpty()) break;
map.put(name, id);
}
for (Map.Entry<String, Integer> mp : map.entrySet()) {
System.out.println(mp.getValue() + " " + mp.getKey());
}
}
}