[java]代码库
package textstudent;
public class People {
private String name;
private String birdate;
private String sex;
private double height;
private double weight;
public People(){
}
public People(String name,String birdate,String sex,double height,double weight){
this.name = name;
this.birdate =birdate;
this.sex = sex;
this.height = height;
this.weight = weight;
}
public String getName() {
return name;
}
public String getBirdate() {
return birdate;
}
public String getSex() {
return sex;
}
public double getHeight() {
return height;
}
public double getWeight() {
return weight;
}
public void setName(String name) {
this.name = name;
}
public void setBirdate(String birdate) {
this.birdate = birdate;
}
public void setSex(String sex) {
this.sex = sex;
}
public void setHeight(double height) {
this.height = height;
}
public void setWeight(double weight) {
this.weight = weight;
}
@Override
public String toString() {
return "姓名:" + name + "\t出生日期:" + birdate + "\t性别:" + sex + "\t身高:" + height +"\t体重:"+ weight ;
}
}
-------------------------------------------------------------------------
package textstudent;
//import javax.lang.model.element.PackageElement;
public class TestPeople {
public static void main(String[] args) {
People[] people = {
new People("林一","1989年8月13日","男",182,63.5),
new People("李红","1999年9月15日","女",176,65.5),
new People("赵高","1998年10月25日","男",189,74),
new People("张力","1991年5月8日","女",186,69),
new People("黄丹","2000年8月15日","女",168,55),
};
People people_ = new People();
for (int i = 1; i <= people.length; i++) {
for (int j = 1; j < people.length-i; j++) {
if (people[j+1].getHeight() < people[j].getHeight()) {
people_ = people[j];
people[j] = people[j+1];
people[j+1] = people_;
}
}
for ( i = 0; i < people.length; i++) {
System.out.println(people[i] + "\n");
}
}
}
}
[代码运行效果截图]