为什么运行失败了,我在eclipse可以运行
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
public class FootballDemo {
public static void main(String[] args) {
//定义HashMap的对象并添加数据
Map <String,String> country=new HashMap <String,String> ();
Scanner ac=new Scanner(System.in);
int i=0;
while(i<3) {
System.out.println("年份");
String key=new Scanner(System.in).next();
System.out.println("国籍");
String value=new Scanner(System.in).next();
country.put(key, value);
i++;
}
//使用迭代器的方式遍历
System.out.println("通过迭代器遍历输出value");
Iterator<String> it=country.values().iterator();
while(it.hasNext()) {
System.out.println(it.next()+" ");
}
//使用EntrySet同时获取key和value
System.out.println("通过entrySet输出key和value值");
Set <Entry<String,String>> entrySet=country.entrySet();
for(Entry<String,String>entry:entrySet) {
System.out.print(entry.getKey()+"-");
System.out.println(entry.getValue());
}
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星