创建新的类存放美女的身高体重,并用for循环来输入各项数据
创建map类来存放身高体重和
创建map类计算平均身高体重,创建类判断并得出结论
在主main中调用
详细代码如下:
import java.util.*;
public class Test4 {
public Map<String,List> getHights(){
List hights=new ArrayList<>();
List wights=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();
hights.add(h);
wights.add(w);//♣♦♥♠
}
Map<String,List> map=new HashMap<>();
map.put(“sg”,hights);
map.put(“tz”,wights);
return map;
}
public Map<String,Integer> getSumHAndSumW(List hights,List wights){
int sumh=0;
for(int h:hights){
sumh+=h;
}
System.out.println(sumh);
int sumw=0;
for(int w:wights){
sumw+=w;
}
System.out.println(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) {
Test4 test4=new Test4();
Map<String,List> sgtz=test4.getHights();
List hights=sgtz.get(“sg”);
List wights=sgtz.get(“tz”);
// List wights=test4.getWights();
Map<String,Integer> map=test4.getSumHAndSumW(hights,wights);
Map<String,Integer> avgM=test4.getAvg(map);
String s=test4.getResult(avgM);
System.out.println(s);
}
}