编程实现:输入班里10名学生的身高,获得身高最高的学生,要求使用对象数组类型方法实现,用My Eclipse写

如题所述

public class Students{
double height;
int id;

}

public class Herght
{
public Students getMaxHeight(Students[] stu){
double maxH = 0;

Students stuMaxHeight = new Students();

for(int i = 0 ; i < stu.length(); i++){
if(stu[i].height>maxH){
stuMaxHeight.id = i+1;
stuMaxHeight.height = stu[i].height;
maxH = stu[i].height;
}

}

System.out.println("第"+stuMaxHeight.id+"个学生身高最高,身高为:"+ stuMaxHeight.height);

return stuMaxHeight;
}

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-08-17
public Students getMaxHeight(Students[] stu)
{
    double height=0.0;
    for(int i=0;i<stu.length();i++)
    {
        for(int j=i+1;j<stu.length();j++)
        {
            if(stu[i]<stu[j])
            {
                heigth=stu[i];
                stu[i]=stu[j];
                stu[j]=height;
            }
        }
    }
    return stu[0];
}

now stu[0] is the highest one

追问

就这么点吗

追答yes , this is bubble sort method , you can get it anywhere ...

have fun:)

guy!

if you want me to help you finish  so  here you are 

the two files

 

相似回答