My output is
java.lang.NumberFormatException: For input string: "String1"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at com.codegym.task.task10.task1019.Solution.main(Solution.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
I learn ocuur a excption,but i do not konw how to solve it.
Please explain the fault of my code ,thank u !
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 name = reader.readLine();
int id = Integer.parseInt(reader.readLine());
if (name.isEmpty())
break;
else
map.put(name,id);
}
for(Map.Entry<String, Integer> pair : map.entrySet()) {
String name = pair.getKey();
int id = pair.getValue();
System.out.println( id + " " + name);
}
}
}