Hi, whats wrong with my code ? thanks.
package com.codegym.task.task10.task1019;
import java.io.*;
import java.util.HashMap;
/*
Functionality is not enough!
Task: The program reads a pair (a number and string) from the keyboard and displays it on the screen.
New task: The program reads pairs (a number and string) from the keyboard and stores them in a HashMap.
Any empty input signifies the end of data entry.
The numbers can be repeated.
The strings are always unique.
The entered data must not be lost!
The program then displays the contents of the HashMap on the screen.
Each pair on a new line.
Requirements:
1. The program must read data from the keyboard.
2. The program should display text on the screen.
3. In the main method, declare a HashMap variable and immediately initialize it.
4. The program should put the pairs read from the keyboard into the HashMap.
5. The program should display the contents of the HashMap in accordance with the conditions.
The key and value are separated by a space. Each value should be on a new line.
*/
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));
int id;
String name;
while (true) {
id = Integer.parseInt(reader.readLine());
name = reader.readLine();
map.put(name, id);
if (name.equals(""))
break;
}
for (String x : map.keySet()) {
System.out.println(map.get(x) + " " + x);
}
}
}