2.0
package com.zhongruan;
import java.util.*;
public class Test4 {
public List getBLs() {
List bls = new ArrayList<>();
Scanner input = new Scanner(System.in);
for (int i = 1; i < 4; i++) {
System.out.println(“请输入第” + i+ “个美女的身高:”);
int h = input.nextInt();
System.out.println(“请输入第” + i + “个美女的体重:”);
int w = input.nextInt();
BL bl=new BL();
bl.setHeight(h);
bl.setWight(w);
bls.add(bl);
}
return bls;
}
public Map<String, Integer> getSumHAndSumW(List<BL> bls) {
//增强for循环
int sumH = 0;
int sumW = 0;
for (BL bl : bls) {
sumH = sumH + bl.getHeight();
sumW = sumW + bl.getWight();
}
System.out.println(sumH+"====="+sumW);
Map map = new HashMap();
map.put("sgh", sumH);
map.put("tzh", sumW);
return map;
}
public Map<String, Integer> getAvg(Map<String, Integer> map) {
int sumH = map.get("sgh");
int sumW = map.get("tzh");
int avgH = sumH / 3;
int avgW = sumW / 3;
Map<String, Integer> avgMap = new HashMap<>();
avgMap.put("pjsg", avgH);
avgMap.put("pjtz", avgW);
return avgMap;
}
public String getResult(Map<String, Integer> avgM) {
int avgH = avgM.get("pjsg");
int avgW = avgM.get("pjtz");
if (avgH > 150 && avgW < 100) {
return "是美女";
} else {
return "不是美女";
}
}
public static void main(String[] args) {
/* a.从浙江工贸选10个美女
b.计算10个美女的身高和 和 体重和
b 计算10美女的平均身高和平均体重
d 判断这批美女是否合格 平均身高》150 平均体重《200*/
Test4 test4 = new Test4();
List<BL> bls= test4.getBLs();
/*List<Integer> hights = sgtz.get("sg");
List<Integer> wights = sgtz.get("tz");*/
Map<String, Integer> map = test4.getSumHAndSumW(bls);
Map<String, Integer> avgM = test4.getAvg(map);
String s = test4.getResult(avgM);
System.out.println(s);
}
}
1.0
package com.zhongruan;
import java.util.ArrayList;
import java.util.List;
public class Test4 {
public static void main(String[] args) {
/* a.从浙江工贸选10个美女
b.计算10个美女的身高和 和 体重和
b 计算10美女的平均身高和平均体重
d 判断这批美女是否合格 平均身高》150 平均体重《200*/
// 1.int ---->Integer boolean---->Boolean
List<Integer> highs = new ArrayList<>();
List<Integer> wights = new ArrayList<>();
highs.add(180);
highs.add(170);
highs.add(150);
wights.add(50);
wights.add(90);
wights.add(55);
System.out.println(highs);
System.out.println(wights);
//增强for循环
int sumH=0;
for(int h:highs){
sumH=sumH+h;
}
System.out.println(sumH);
int sumW=0;
for(int w:wights){
sumW=sumW+w;
}
System.out.println(sumW);
int avgH=sumH/highs.size();
int avgW=sumW/highs.size();
System.out.println(avgH);
System.out.println(avgW);
// avgH=50
if(avgH>150 && avgW<200 ){
System.out.println("是美女");
}else{
System.out.println("不是美女");
}
}
}