#连续输入三组身高和体重,判断是否满足所设条件,使用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("不合格");
}
}