• 0926-----homework(2)


     1 /**
     2   *homework0926
     3   *@author:kai li
     4   */
     5 package com.kai.li.homework0926;
     6 import java.util.List;
     7 import java.util.ArrayList;
     8 import java.util.Arrays;
     9 import java.util.HashMap;
    10 import java.util.Map;
    11 import java.util.Scanner;
    12 import java.util.Random;
    13 /**
    14   *following class is client 
    15   */
    16 public class HomeWork0926{
    17     public static void main(String[] args)throws Exception{
    18         
    19         /**
    20           *question one
    21           */
    22 
    23         /*create data source*/
    24 
    25         List<String> keyList=Arrays.asList("1930","1934","1938","1950","1954","1958","1962","1966","1970","1974","1978","1982","1986","1990","1994","1998","2002","2006","2010","2014");
    26         List<String> valueList=Arrays.asList("乌拉圭","意大利","意大利","乌拉圭","西德","巴西","巴西","英格兰","巴西","西德","阿根廷","意大利","阿根廷","西德","巴西","法国","巴西","意大利","西班牙","德国");
    27         Map<String,String> footballMap=new HashMap<>();
    28         for(int i=0;i<keyList.size();i++){
    29             footballMap.put(keyList.get(i),valueList.get(i));
    30         }
    31 
    32         /*query with years*/
    33          
    34         System.out.print("请输入年份:");    
    35         Scanner scanner=new Scanner(System.in);
    36         String strKey=scanner.nextLine();
    37         if(!footballMap.containsKey(strKey))
    38             System.out.println("没有举办世界杯");
    39         else
    40             System.out.println("世界杯冠军是: "+footballMap.get(strKey));
    41 
    42         /*query with countrys */
    43         
    44         System.out.print("请输入国家名称:");
    45         String strValue=scanner.nextLine();
    46         if(!footballMap.containsValue(strValue))
    47             System.out.println(strValue+"没有得过世界杯的冠军");
    48         else{
    49             System.out.println(strValue+"得冠军年份是:");
    50             footballMap.keySet().stream().filter(i->strValue.equals(footballMap.get(i))).sorted().forEach(System.out::println);    //filter the data then sorted then println
    51         }
    52 
    53          /**
    54           *question two
    55           */
    56 
    57         /*create data source*/
    58 
    59         List<String> footballTeam=Arrays.asList("科特迪瓦队","阿根廷队","澳大利亚队","塞尔维亚队","荷兰队","尼日利亚队","日本队","美国队","中国队","新西兰队","巴西队","比利时队","韩国队","喀麦隆队","洪都拉斯队","意大利队");
    60         List<ArrayList<String>> footballTeams=new ArrayList<ArrayList<String>>();
    61     footballTeams=Arrays.asList(new ArrayList<String>(),new ArrayList<String>(),new ArrayList<String>(),new ArrayList<String>());
    62 
    63         /*create array of diffrent random number*/
    64 
    65         int[] randomArray=new int[16];
    66         Random random=new Random();
    67         for(int i=0;i<randomArray.length;i++){
    68             int r;
    69             r=random.nextInt(16);
    70             randomArray[i]=r;
    71             for(int j=0;j<i;j++){
    72                     if(r==randomArray[j]){
    73                         i--;
    74                         break;
    75                     }
    76                }
    77         }
    78 
    79         /*grouping*/
    80     
    81         for(int i=0;i<4;i++){
    82             for(int j=i*4;j<(i+1)*4;j++){
    83                     footballTeams.get(i).add(footballTeam.get(randomArray[j]));
    84                }
    85         }
    86         System.out.println(footballTeams);
    87     }
    88 }
  • 相关阅读:
    Gson中@SerializedName 注解使用
    centos8 安装mongodb4.4
    ssh 连接manjaro失败
    git保存仓库的账号密码
    centos 安装etcd
    kubeadm部署k8s 拉取基础镜像
    centos 安装cloc 代码统计工具
    centos7 安装mongodb
    shell获取时间戳
    最详细的阿里云ECS服务器CentOS7上安装tomcat8服务(三)
  • 原文地址:https://www.cnblogs.com/kaililikai/p/5915191.html
Copyright © 2020-2023  润新知