用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

People类

2021-12-12 作者: GuanTou举报

[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");
            }
        }
    }
}







[代码运行效果截图]


People类


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...