求助找错

package com.tencent.lqh.day1;

public class test {
    public static void main(String[] args) {
        Student[] stu = new Student[20];
        for (int i=0; i< stu.length; i++){
            stu[i].number = i+1;
            int tempnum = (int) Math.round(Math.random()*10) % 3;
            // 班级随机数0 为3 班级
            stu[i].state = tempnum == 0 ? 3 : tempnum;
            // 成绩随机数
            stu[i].score = (int) Math.round(Math.random()*100);
            System.out.println("学号:"+stu[i].number+"成绩"+stu[i].score+"班级"+stu[i].state);
        }
        System.out.println("------------------------");
        for (Student stu1: stu){
            System.out.println("学号:"+stu1.number+"成绩"+stu1.score+"班级"+stu1.state);
        }
        System.out.println("------------------------");
        for (int i=0; i< stu.length; i++){
            if (stu[i].state == 3){
                System.out.println("学号:"+stu[i].number+"成绩"+stu[i].score+"班级"+stu[i].state);
            }
        }
    }
}

class Student {
    static int number;
    static int state;
    static int score;
}
  • 正常结果应该如下:
学号:1成绩11班级3
学号:2成绩3班级3
学号:3成绩16班级3
学号:4成绩9班级3
学号:5成绩40班级2
学号:6成绩74班级3
学号:7成绩19班级3
学号:8成绩56班级1
学号:9成绩27班级1
学号:10成绩84班级3
学号:11成绩57班级2
学号:12成绩14班级3
学号:13成绩61班级2
学号:14成绩58班级1
学号:15成绩36班级3
学号:16成绩39班级1
学号:17成绩64班级3
学号:18成绩43班级1
学号:19成绩79班级2
学号:20成绩44班级2
  • 目前结果如下:
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
学号:20成绩44班级2
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容