java.编写一个包含姓名,身高属性的Person类,

2020-05-04 教育 143阅读
import java.util.ArrayList;
import java.util.List;
public class Person {
private String name="";//姓名
private int height=0;//身高

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public static void main(String[] args) {
Person per1=new Person();
per1.setName("tom");
per1.setHeight(163);
Person per2=new Person();
per2.setName("jack");
per2.setHeight(175);
Person per3=new Person();
per3.setName("toto");
per3.setHeight(170);
System.out.println(setPersonHeight2(per1,per2,per3));
}
public static String setPersonHeight(Person...person){
List pList=new ArrayList();
for (int i = 0; i < person.length; i++) {
}
return "";
}
public static String setPersonHeight2(Person...person){
for(int i=1;i for(int j=i;j>0;j--){
if (person[j].getHeight() int temp=person[j-1].getHeight();
String name=person[j-1].getName();
person[j-1].setHeight(person[j].getHeight());
person[j-1].setName(person[j].getName());
person[j].setHeight(temp);
person[j].setName(name);
}else break;
}
}

if(person.length>0){

/***
* 测试
*/
// for (int i = 0; i < person.length; i++) {
// System.out.println(person[i].getHeight()+"---"+person[i].getName());
// }

return "姓名:"+person[person.length-1].getName()+" 身高:"+person[person.length-1].getHeight();
}else{
// System.out.println("请传入Person对象");
return "请传入Person对象";
}
}
/***
* 测试数组
* @param args
* @return
*/
public static int[] insertSort(int[] args){//插入排序算法
for(int i=1;i for(int j=i;j>0;j--){
if (args[j] int temp=args[j-1];
args[j-1]=args[j];
args[j]=temp;
}else break;
}
}
return args;
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com