class Student{
private String id;
private String name;
private String sex;
private String phone;
private String chengji;
public Student(String i,String n,String s,String p,String c){
this.id=i;
this.name=n;
this.sex=s;
this.phone=p;
this.chengji=c;
}
public String getId(){
return this.id;
}
public String getName(){
return this.name;
}
public String getSex(){
return this.sex;
}
public String getPhone(){
return this.phone;
}
public String getChengji(){
return this.chengji;
}
;
}
class Test{
public static void main(String[] args){
Student s1=new Student("学号: 017","姓名:张大华","性别:男","电话:5887185","java成绩: 60");
Student s2=new Student("学号: 018","姓名:张小华","性别:男","电话:5887185","java成绩: 80");
System.out.println(s1.getId());
System.out.println(s1.getName());
System.out.println(s1.getSex());
System.out.println(s1.getPhone());
System.out.println(s1.getChengji());
System.out.println();
System.out.println(s2.getId());
System.out.println(s2.getName());
System.out.println(s2.getSex());
System.out.println(s2.getPhone());
System.out.println(s2.getChengji());
System.out.println();
float ave;
ave=(85+80)/2;
System.out.println("两人的平均成绩为:"+ave);
}
}
为什么运行结果中ave=82.0,改了分数后,结果仍为82.0,错在哪儿?另外此类中求平均成绩可以要哪种方法?求平均成绩应该怎么求?,望各位帮忙解答,谢谢