使用java实现面向对象编程怎样2.读入一个字符串,表示一个年份,输出该年的世界杯冠军 - 爱问答

(爱问答)

使用java实现面向对象编程怎样2.读入一个字符串,表示一个年份,输出该年的世界杯冠军

怎样使用Map   读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。


简单的参考

 public static void main(String[]args) {
       HashMap < Integer,String  > ch = new HashMap < Integer,String > ();
       ch.put(1930, "乌拉圭");
       ch.put(1934, "意大利");
       ch.put(1938, "意大利");
       ch.put(1950, "乌拉圭");
       ch.put(1954, "联邦德国");
       ch.put(1958, "巴西");
       ch.put(1962, "巴西");
       ch.put(1966, "英格兰");
       ch.put(1970, "巴西");
       ch.put(1974, "联邦德国");
       ch.put(1978, "阿根廷");
       ch.put(1982, "意大利");
       ch.put(1986, "阿根廷");
       ch.put(1990, "联邦德国");
       ch.put(1994, "巴西");
       ch.put(1998, "法国");
       ch.put(2002, "巴西");
       ch.put(2006, "意大利");
       ch.put(2010, "西班牙");
       ch.put(2014, "德国");
       ch.put(2018, "法国");
       Scanner sc = new Scanner(System.in);
       int y = sc.nextInt();
       if(ch.containsKey(y))
           System.out.println(ch.get(y));
       else
           System.out.println("输入年份错!");
   }

相关标签:java

下一篇:Mastercam2017为什么不能自动特征钻孔

上一篇:现在某些数据已标红,怎样标记和标红数据相同的数据

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?