zoukankan      html  css  js  c++  java
  • 找出每个区域最大的PM2.5数据

    package test;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set;
    //找出每个区域最大的PM2.5数据
    public class testCollection {
    
        public static void getMaxData(String[] positions,int[] datas){
            HashMap<String,Integer> hashMap = new HashMap<String, Integer>();
            for(int i = 0;i<positions.length;i++){
                String position = positions[i];
                if(!(hashMap.containsKey(position))||datas[i]>hashMap.get(position)){
                    hashMap.put(position,datas[i]);
                }
            }
            Set<Map.Entry<String,Integer>> entrySet = hashMap.entrySet();
            for(Map.Entry<String,Integer> set:entrySet){
                System.out.println("区域为"+set.getKey()+"检测到的PM2.5最大数据为"+set.getValue());
            }
    
        }
    
        public static void main(String[] args) {
            String[] positions = {"王府井","天坛","通州","昌平","农展馆","怀柔","朝阳","海淀","王府井",
                    "通州","海淀","农展馆","王府井","顺义","昌平","朝阳","顺义"};
            int[] datas = {211,322,363,267,356,376,235,265,357,355,210,201,377,399,393,288,299};
    
            testCollection.getMaxData(positions,datas);
    
        }
    
    }
    

      结果

    区域为农展馆检测到的PM2.5最大数据为356
    区域为海淀检测到的PM2.5最大数据为265
    区域为通州检测到的PM2.5最大数据为363
    区域为怀柔检测到的PM2.5最大数据为376
    区域为王府井检测到的PM2.5最大数据为377
    区域为天坛检测到的PM2.5最大数据为322
    区域为昌平检测到的PM2.5最大数据为393
    区域为朝阳检测到的PM2.5最大数据为288
    区域为顺义检测到的PM2.5最大数据为399
    

      

  • 相关阅读:
    c++单例模式为什么不在析构函数中释放静态的单例对象(转)
    Ubuntu 树莓派2b交叉编译环境
    多线程std::cout 深入研究
    c++11的 move并没有实际move
    RTC时间设置
    QT 第三方串口库COM10以上无法读取问题
    ubuntu gcc-5 安装
    STM32正交编码器驱动电机
    (转)layoutSubviews总结
    自定义视图控制器切换(iOS)
  • 原文地址:https://www.cnblogs.com/seven717/p/12885256.html
Copyright © 2011-2022 走看看