package homework001; import java.util.HashMap;
import java.util.Scanner; public class Map { public static void main(String[] args) { java.util.Map<String, String> m1 = new HashMap<>();
m1.put("1930", "乌拉圭");
m1.put("1934", "意大利");
m1.put("1938", "意大利");
m1.put("1950", "乌拉圭");
m1.put("1954", "西德");
m1.put("1958", "巴西");
m1.put("1962", "巴西");
m1.put("1966", "英格兰");
m1.put("1970", "巴西");
m1.put("1974", "西德");
m1.put("1978", "阿根廷");
m1.put("1982", "意大利");
m1.put("1986", "阿根廷");
m1.put("1990", "西德");
m1.put("1994", "巴西");
m1.put("1998", "法国");
m1.put("2002", "巴西");
m1.put("2006", "意大利");
m1.put("2010", "西班牙");
m1.put("2014", "德国");
Scanner sc = new Scanner(System.in);
System.out.println("请输入年份");
String str = sc.nextLine();
if(m1.containsKey(str)==false)
{
System.out.println(str+"年没有举办世界杯");
}
else
{
System.out.println(str+"年的夺冠球队是:"+m1.get(str));
} Scanner sc1 = new Scanner(System.in);
System.out.println("请输入夺冠球队");
String str1 = sc1.nextLine();
if(m1.containsValue(str1)==false)
{
System.out.println(str1+"队没有获得过冠军");
}
else
{
System.out.println(str1+"队的夺冠年份是:");
for(String k :m1.keySet())
{
if(m1.get(k).equals(str1))
{
System.out.print(" "+k);
}
} } } }