WorldCup

public class WorldCup {
    public static void main(String[] args) {
   Map Footballteam = new HashMap();
        String[] winner = {"乌拉圭","意大利","意大利","乌拉圭","西德","巴西","巴西","英格兰",
                           "巴西","西德","阿根廷","意大利","阿根廷","西德","巴西","法国",
                           "巴西","意大利","西班牙","德国",};
        int year = 1930;
        for (String string:winner){
//            System.out.print(year+"----");
            Footballteam.put(year,string);
            if (year == 1938){
                year += 12;
            }
            else {
                year += 4;
            }
//            System.out.println(string);
        }
        while (true) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入年份,输0退出");
            int inputyear = scanner.nextInt();
            if (inputyear == 0){
                break;
            }
            if (Footballteam.containsKey(inputyear)){
                System.out.println("冠军是:"+Footballteam.get(inputyear));
            }
            else {
                System.out.println("没有举办世界杯");
            }
            System.out.println("请输入球队名");
            String teamname = scanner.next();
            if (Footballteam.containsValue(teamname)){
                Set array = Footballteam.keySet();
                for (Integer integer:array){
                    Footballteam.get(integer);
                    if (Footballteam.get(integer).equals(teamname)){
                        System.out.println(integer);
                    }
                }
            }
            else {
                System.out.println(teamname+"没有获得过冠军");
            }

        }

    }
}

你可能感兴趣的:(WorldCup)