本文主要是介绍Java的8 大基本类型的包装类和美女选妃案例的两种写法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
8 大基本类型的包装类
包装类的类型 | 包装的类型 |
---|---|
Byte | byte |
Short | short |
Integer | int |
Long | long |
Float | float |
Double | double |
Character | character |
Boolean | boolean |
一.用列表的方式实现美女选妃
package com.zhongruan;
import java.util.*;
public class Zuoye {
public List getHighs(){
List highs = new ArrayList<>();
highs.add(180);
highs.add(170);
highs.add(160);
return highs;
}
public List getwighs(){
List weights=new ArrayList<>();
weights.add(50);
weights.add(60);
weights.add(70);
return weights;
}
public Map<String,Integer>getSumHAndSumW(List highs,List wights){
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);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){Zuoye zuoye=new Zuoye();List<Integer> highs=zuoye.getHighs();List<Integer> weights=zuoye.getwighs();Map<String, Integer> map = zuoye.getSumHAndSumW(highs,weights);Map<String, Integer> avgM = zuoye.getAvg(map);String s = zuoye.getResult(avgM);System.out.println(s);
}
}
二.用列表的方式实现美女选妃
package com.zhongruan;
import java.util.Scanner;
public class Xf{
public static void main(String[] args){
Scanner sr=new Scanner(System.in);
System.out.println(“请输入美女人数:”);
int length=sr.nextInt();
//计算身高总和
int data[] = {170,160, 165, 166, 157, 163,152, 167,158, 169};
int zh=0;
for(int i = 0; i < length; i++) {
zh = zh+ data[i];
}
System.out.println(“身高总和:”+zh);
//计算体重总和int data1[] = {106, 80, 110, 150, 147, 100,100, 108,135, 124};int tzh=0;for(int i = 0; i < length; i++) {tzh = tzh+ data1[i];}System.out.println("体重总和:"+tzh);double pjsg=zh/length;double pjtz=tzh/length;System.out.print("平均身高是:"+pjsg);System.out.print("\n平均体重是:"+pjtz);if (pjsg>150 && pjtz<200 ){System.out.print("\n合格");}else {System.out.print("\n不合格");}
}
这篇关于Java的8 大基本类型的包装类和美女选妃案例的两种写法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!