java - 循环中的java输入给出不匹配异常
问题描述
这是下面的代码和它的输入,它显示第二个循环不匹配,有人可以解释为什么
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class MapDemo {
public static void main(String[] args) {
HashMap<Integer, String> hmap = new HashMap<>();
Scanner in = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
Integer a = in.nextInt();
String b = in.next();
hmap.put(a, b);
}
for (Map.Entry<Integer, String> m : hmap.entrySet()) {
System.out.println(m.getKey() + " " + m.getValue());
}
}
}
输入:
10654
Max Bupa Health Insurance
10321
SBI Health Insurance
20145
IFFCO Tokio Two Wheeler Insurance
解决方案
推荐阅读
- php - 如何根据经纬度应用过滤器?
- azure - 如何使用 Azure SignalR 服务托管 SignalR 集线器?
- python - 如何解决 AttributeError:SMTP_SSL 实例在 Python 中没有属性“__exit__”?
- java - java FX - 日历中的 Datepicker 天数变灰
- php - 从 Woocommerce 管理员编辑订单页面中删除运输行
- python - 查找重复的行,将某个列乘以重复的数量,删除重复的行
- java - 使用 nd4j 的 Sigmoid 导数
- html - 我想一天只显示一次弹出窗口
- odata - “模型无法解析名为 'Product' 的类型。当模型可用时,每个类型名称都必须解析为有效类型。” 在 D365 中
- slf4j - 如何使用 Lombok 创建 Logger 对象?