Class类中有错,数组的定义和初始化哪里错了,求大神指教
import java.util.Scanner;public class Classtest {
public static void main(String[] agrs) {
Class.search p=new Class().new search();
System.out.println("请输入一位学生学号(学号在1-10之间):");
Scanner tt=new Scanner(System.in);
int read=tt.nextInt();
tt.close();
p.sea(read);
Class q=new Class();
System.out.println("班级的平均分:"+q.average);
System.out.printf("班级的最高分和最低分分别为:%4d%4d",q.max,q.min);
}
}
public class Student {
int sno;
String name;
int grade;
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public Student (){
}
public Student(int sno,String name,int grade){
this.sno=sno;
this.name=name;
this.grade=grade;
}
public Student(int sno,String name){
this(sno,name,0);
}
}
public class Class {
Student []a=new Student[10];
a[0]=new Student(1,"王冬",72);
a[1]=new Student(2,"雨浩",76);
a[2]=new Student(3,"叶辰",86);
a[3]=new Student(4,"唐三",83);
a[4]=new Student(5,"王菲",94);
a[5]=new Student(6,"杨洋",80);
a[6]=new Student(7,"欧阳淼",77);
a[7]=new Student(8,"汪峰",85);
a[8]=new Student(9,"杨琳",64);
a[9]=new Student(10,"马龙",79);
class search{
public void sea(int x) {
for(int i=0;i<a.length;i++) {
if(a[i].sno==x)
System.out.printf("输出的学生成绩为:%d\n",a[i].grade);
}
}
}
int sum=0,average;
int max=a[0].grade, min=a[0].grade;
for(int i=0;i<a.length;i++) {
sum=sum+a[i].grade;
}
for(int j=0;j<a.length;j++) {
if(max<a[j].grade)
max=a[j].grade;
}
for(int k=0;k<a.length;k++) {
if(min>a[k].grade)
min=a[k].grade;
}
average=sum/a.length;
}