美文网首页
求助找错

求助找错

作者: 又增加了奇奇怪怪的知识 | 来源:发表于2021-01-09 18:09 被阅读0次
    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
    

    相关文章

      网友评论

          本文标题:求助找错

          本文链接:https://www.haomeiwen.com/subject/fxacaktx.html