完整代码:
public class {
public static void main(String[] args) {
//创建20个学生对象:
Student[] std = new Student[20];
for(int i = 0;i < std.length;i++) {
std[i] = new Student();
//学号为1~20:
std[i].number = (i+1);
//年级Math.random[0.0 1.0)*6-->[0.0 6.0)-->(int)[0 6)+1-->[1 6]
std[i].state = (int)(Math.random()*6) + 1;
//成绩[0 100]
std[i].score = (int)(Math.random()*100) + 1;
}
}
//定义类Student:
class Student{
//包含三个属性:
int number;//学号
int state;//年级
int score;//成绩
//遍历学生属性信息方法:
public String info() {
return "学号:"+number+"\t"+"年级:"+state+"\t"+"成绩:"+score;
}
//遍历20个学生的属性信息:
public void arrayergo(Student[] std) {
for(int i = 0;i < std.length;i++){
System.out.println(std[i].info());
}
}
//问题一:打印出3年级(state值为3)的学生信息:
public void statefind(Student[] std,int state) {
for(int i = 0;i < std.length;i++) {
if(std[i].state==state) {
System.out.println(std[i].info());
}
}
}
}
}
图片:

main方法是静态 你的内部类不是静态
非静态内部类不能在静态方法中引用
Student定义成static即可
把student单独抽出来写一个文件,另外实体类里不要写这种方法
你的main方法是静态的,class Student 也要是静态的才能直接使用