Java数组相关的题求助
package com.gf.test01;
import java.util.Scanner;
public class Practice3 {
public static void main(String[] args) {
double sum=0.0;
double avg=0.0;
Student[] st=new Student[5];
System.out.println("-------输入数据--------");
for(int i=0;i<st.length;i++) {
Scanner sc=new Scanner(System.in);
st[i]=new Student();
System.out.print("输入姓名:");
st[i].setName(sc.next());
System.out.print("输入年龄:");
st[i].setAge(sc.nextInt());
//计算总年龄
sum+=st[i].getAge();
}
for(Student s:st) {
System.out.println("姓名:"+s.getName()+"\t年龄:"+s.getAge());
//计算平均值
avg=sum/st.length;
}
System.out.println("年龄平均值"+avg);
}
}
class Student{
private String name;
private int age;
public Student() {
}
public Student(String name,int age) {
this.name=name;
this.age=age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}