List和Map小应用

#连续输入三组身高和体重,判断是否满足所设条件,使用List和Map方法

package Day2;
import com.sun.imageio.plugins.common.I18N;
import java.util.*;

public class Buttiful {
    public static void main(String[] args) {
        List<Integer> high = new ArrayList<>();
        List<Integer> wight = new ArrayList<>();
        //创建两个表用于存储身高和体重
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.print("High:");
            int h = sc.nextInt();
            high.add(h);//添加至high表中
            System.out.print("Wight:");
            int w = sc.nextInt();
            wight.add(w);//添加至weight表中
        }
        sc.close();//关闭输入流
        System.out.println(high);
        System.out.println(wight);
        Map<String, Integer> map = getAvg(high,wight);
        judge(map);

    }
    //添加数据的平均值
    static Map<String,Integer> getAvg( List<Integer> high, List<Integer> wight){
        Map<String, Integer> map=new HashMap<>();
        int sumH=0,sumW=0;
        for (Integer h : high) {
            sumH+=h;
        }
        for (Integer w :wight) {
            sumW+=w;
        }
        int AvgH=sumH/high.size();
        int AvgW=sumW/wight.size();
        map.put("AvgH",AvgH);
        map.put("AvgW",AvgW);
        return map;

    }
    static void judge(Map<String,Integer> map){//判断
        int ah=map.get("AvgH");
        int aw=map.get("AvgW");
        if(ah>165&&aw<55)
            System.out.println("合格");
        else
            System.out.println("不合格");
    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值