多易javaSE基础 day4 课程日志 电影平均分

今天解决了昨天数据分析案例遇到的问题.
出现了空指针错误,是因为数据源有一条记录是空的,只需要在解析json数据时加上判断语句即可.若为空,就赋值为0.

if (rate == null){
                rate = 0.0;
            }

今天讲了移位运算符,深入讨论了很多.int类型数据移位运算是要与32取膜.
接下来要尝试把电影平均分做出来,做完这个就开始学习RPC项目.
电影平均分计算代码块如下:

 Set<Map.Entry<String, Double>> entrySet1 = rateMap.entrySet();
        Set<Map.Entry<String, Integer>> entrySet = countMap.entrySet();

//        for (Map.Entry<String, Integer> ent:entrySet){
//            Integer count = ent.getValue();
//        }
        for (Map.Entry<String, Double> ent:entrySet1){  //计算每部电影的平均分
            DecimalFormat df = new DecimalFormat("#.00");

            String movieId = ent.getKey();
            Double rate = ent.getValue();
            Integer count = countMap.get(movieId);
            rateMap.put(movieId, Double.valueOf(df.format( rate/count)));
        }

猜你喜欢

转载自blog.csdn.net/weixin_44855583/article/details/107598086