Output :
Id=1 Name=String1
null
Id=2 Name=
I was getting 'InputMismatchException', and I handled it
package com.codegym.task.task10.task1019;
import java.io.*;
import java.util.*;
/*
Functionality is not enough!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int id = Integer.parseInt(reader.readLine());
String name = reader.readLine();
System.out.println("Id=" + id + " Name=" + name);
HashMap<Integer, String> map = new HashMap<Integer, String>();
Scanner sc = new Scanner(System.in);
Integer x;
String s;
try {
for (int i=0; ; i++) {
x = sc.nextInt();
s = sc.nextLine();
if (x != null && !s.equals(null)) {
map.put(x,s);
}
else {
break;
}
}
} catch (InputMismatchException e) {
System.out.println(e.getMessage());
}
for (Map.Entry<Integer, String> pair : map.entrySet()) {
System.out.println("Id=" + pair.getKey() + " Name=" + pair.getValue());
}
}
}