首页上一页 1 下一页尾页 1 条记录 1/1页
对象students stu和对象数组类型参数students stu,
发表在Java图书答疑
2013-12-05
是否精华
是
否
版块置顶:
是
否
对象students stu为什么没实例化就引用属性avg=(stu.java+stu.database.stu.html)/3,还有对象数组类型参数students stu,
if(stu[i].height!=0){
all=all+stu[i].height;
count++;
}
//对象类型参数
public class students{
float java=0;float database=0;float html=0;
}
public class score{
public float getavg(students stu){
float avg=0;
avg=(stu.java+stu.database.stu.html)/3
return avg;
}
}
//对象数组类型参数
public class students{
float height;
}
public class Height{
public float getAVGheight(students[] stu ){
float avgheight=0;
float all=0;int count=0;
for(int i=0;i<stu.length;i++){
if(stu[i].height!=0){
all=all+stu[i].height;
count++;
}
}
avgheight=all/count;
return avgheight;
}
}
if(stu[i].height!=0){
all=all+stu[i].height;
count++;
}
//对象类型参数
public class students{
float java=0;float database=0;float html=0;
}
public class score{
public float getavg(students stu){
float avg=0;
avg=(stu.java+stu.database.stu.html)/3
return avg;
}
}
//对象数组类型参数
public class students{
float height;
}
public class Height{
public float getAVGheight(students[] stu ){
float avgheight=0;
float all=0;int count=0;
for(int i=0;i<stu.length;i++){
if(stu[i].height!=0){
all=all+stu[i].height;
count++;
}
}
avgheight=all/count;
return avgheight;
}
}