11.MAP查询每年的世界杯冠军
来源:互联网 发布:usb网络打印服务器 编辑:程序博客网 时间:2024/05/05 09:59
/*
(Map)利用Map,完成下面的功能:
从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该
年没有举办世界杯,则输出:没有举办世界杯。
*/
import java.util.*;
class ChampionMap{
Map<String ,String> a = new HashMap<String, String>();
boolean bl;
void addChampion(){
a.put("2006","意大利");
a.put("2002","巴西");
a.put("1998","法国");
a.put("1994","巴西");
a.put("1990","德国");
a.put("1986","阿根廷");
a.put("1982","意大利");
a.put("1978","阿根廷");
a.put("1974","德国");
a.put("1970","巴西");
a.put("1966","英格兰");
a.put("1962","巴西");
a.put("1958","巴西");
a.put("1954","德国");
a.put("1950","乌拉圭");
a.put("1938","意大利");
a.put("1934","意大利");
a.put("1930","乌拉圭");
}
void checkChampion(){
Scanner sc= new Scanner(System.in);
System.out.println("Input year");
String str = sc.next();
bl = a.containsKey(str);
if(bl==true) {
System.out.println(a.get(str));
}
else
System.out.println("没有举办世界杯");
}
void checkChampionName(){
private int count=0;
Scanner sc = new Scanner (System.in);
System.out.println("Input Country Name");
String str=sc.next();
Set<Map.Entry<String,String>> mapEntry = a.entrySet();
Iterator <Map.Entry<String,String>> it= mapEntry.iterator();
while(it.hasNext()){
Map.Entry<String,String> me =it.next();
if(me.getValue().equals(str)){
count++;
System.out.println("year="+me.getKey());
}
}
if(count==0){
System.out.println("没有获得过世界杯");
}
}
}
public class D1{
public static void main(String args[]){
ChampionMap cl= new ChampionMap();
cl.addChampion();
// cl.checkChampion();
cl.checkChampionName();
}
}
- 11.MAP查询每年的世界杯冠军
- 历届世界杯的冠军和最佳射手
- 历届世界杯冠军
- 盘点世界杯中走下神坛的卫冕冠军们
- 历届世界杯冠军队全家福
- 历届世界杯冠军队全家福
- 世界杯绝对冠军:中国房地产足球队
- 历届世界杯冠军队伍介绍
- 本人对2006年世界杯冠军归属的预测,德国夺冠!
- 超级搞笑 中国队勇夺世界杯冠军
- 产生冠军 【map 建图】
- 产生冠军 2094(map和set的结合使用)
- [世界杯]世界杯的哲学思想
- orale 查询每年、每月、每日统计量的sql语句
- orale 查询每年、每月、每日统计量的sql语句
- mysql查询每天每周每月每年的数据方法
- HDU 2094 产生冠军 map
- 2014世界杯冠军预测图:基于大数据与JavaScript
- js中innerHTML用法
- CarParts3
- char,nchar,varchar,nvarchar之间的区别
- mt9d131 驱动简介
- Ubuntu上安装启动SSH Server
- 11.MAP查询每年的世界杯冠军
- 详细介绍ORACLE sqlplus命令
- 一天一个设计模式(2): 外观模式
- Xen 环境配置
- rsync+inotify 配置实时同步服务器
- windows取得串口列表
- Java 线程池的原理与实现
- cocos2d-x学习笔记(二)基本概念与文本
- Oracle数据安全面面观 ORACLE教程 教程作者:づ★sl战神 教程来源:不详 教程栏目:ORACLE教程