java:世界杯查询

Problem Description

1.从命令行读入一个队名,输出该队获得冠军是哪一年(以下面五届数据作为基础数据)。如果该队没有获得冠军,则输出:队名+“ lose the championship!”。
2.下面是五届世界杯数据:

届数 举办年份 举办地点 冠军

第一届,1930年,Uruguay,Uruguay;

第三届,1938年,France,Italy;

第五届,1954年,Swiss,West Germany;

第七届,1962年,Chile,Brazil;

第十三届,1986年,Mexico,Argentina;

Input Description

Italy

Output Description

1938

java代码

public class Main{
	public static void main(String[] args){
		HashMap<String, Integer> map = new HashMap<Strng, Integer>();
		map.put(1930, Uruguay);
		map.put(1938, Italy);
		map.put(1954, West Germany);
		map.put(1962, Brazil);
		map.put(1986, Argentina);
		Scanner input = new Scanner(System.in);
		String str = input.NextLine();
		Set<Integer> keys = map.keySet();
		if(map.containsValue(str) == true){
			for(Integer temp : keys){
				if(map.get(temp) == str){
					System.out.println(temp);
				}
			}
		}else{
			System.out.println(str+" lose the championship!");
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值