9 String9
8 String8
7 String7
10 String10
6 String6
...
...
how it is possible to fix?
LinkedHashMap makes correct output order. but task wants HasMap to be displayed which is always mixed.
package com.codegym.task.task10.task1019;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.LinkedHashMap;
/*
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<String, Integer>();
while (true) {
String input = reader.readLine();
if (input == null) {
break;
}
int number = Integer.parseInt(input);
String name = reader.readLine();
if (name.isEmpty()) {
break;
}
map.put(name, number);
}
for (Map.Entry<String, Integer> pair : map.entrySet()) {
System.out.println(pair.getValue() + " " + pair.getKey());
}
}
}