zoukankan      html  css  js  c++  java
  • Java 世界杯查询

    题目描述

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

    2.下面是五届世界杯数据:

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

    第一届,1930年,Uruguay,Uruguay;

    第三届,1938年,France,Italy;

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

    第七届,1962年,Chile,Brazil;

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

    3.要求(用Map实现,下面的m即是Map对象):下面是后半部分代码,请补充前半部分:

                     if(m.get(temp).equals(str)){
                         System.out.println(temp);
                     }
                 }
              }else{
                   System.out.println( str+" lose the championship!");
              }
         }
    }

    输入描述

    Italy

    输出描述

    1938

    import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.*;
    
    
    
    public class Main 
    {
    
    	public static void main(String[] args) 
    	{
    		Scanner cin = new Scanner(System.in);
    	    Map m = new HashMap();
    	    m.put("1930", "Uruguay");
    	    m.put("1938", "Italy");
    	    m.put("1954", "West Germany");
    	    m.put("1962", "Brazil");
    	    m.put("1986", "Argentina");
    	    String str = cin.nextLine();
    	    if (m.containsValue(str)==true)
    	    {
    	    	Set keySet = m.keySet();
    	    	Iterator it = keySet.iterator();
    	    	while (it.hasNext())
    	    	{
    	    		Object temp = it.next();
    	    		///////////////////////////////
    	    		if (m.get(temp).equals(str)){
    	    		System.out.println(temp);
    	    		}
    	    	}
    	    }
    	    else
        	{
        		System.out.println(str+" lose the championship!");
        	}
    	}
    
    }
    //浪漫Chopin ,烂漫代码。
    
  • 相关阅读:
    nginx不支持pathinfo模式解决方法
    php只保留两位小数
    分享图文到QQ空间
    android 使用信鸽推送通知栏不显示推送的通知?
    Editetext获取焦点后让输入软键盘中出现搜索按键
    Android EditText的使用过程中遇到的问题
    在线根据现有apk生成指定id的推广apk (已过时)
    @Validated和@Valid区别
    idea快捷键使用总结
    大概
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451293.html
Copyright © 2011-2022 走看看