xzdjsnb 2022-03-29 11:23 采纳率: 92.2%
浏览 45
已结题

为什么调不到state方法,


public class ExerTest3{
    public static void main(String[] args) {
        Student8[] test = new Student8[20];
         for(int i = 0;i < test.length;i++) {
             test[i] = new Student8();
             test[i].number = i+1;
             test[i].state = (int)(Math.random()*6+1);
             test[i].score = (int)(Math.random()*101+1);
         }
             test[i].state(test, 3);
      } 
   }
 
class Student8 {
    int number,state,score;
    /**
     * 
     * @Description  输出学生信息
     * @author xiong
     * @date 2022年3月29日上午11:17:12
     * @param test
     */
    public void info(Student8[] test ) {
        System.out.println("学生学号:" + number + "  学生年级:" + state
                + " 学生成绩: " + score);
    }
    /**
     * 
     * @Description  找出相同年级的学生
     * @author xiong
     * @date 2022年3月29日上午11:16:27
     * @param test  
     * @param state
     */
    public void state(Student8[] test,int state) {
        for(int i = 0;i < test.length;i++) {
             if(test[i].state == state) {
                 test[i].info(test);
             }
        
        }
    }
}
  • 写回答

6条回答 默认 最新

  • CSDN专家-sinJack 2022-03-29 11:33
    关注
     
    public class ExerTest3{
        public static void main(String[] args) {
            Student8[] test = new Student8[20];
             for(int i = 0;i < test.length;i++) {
                 test[i] = new Student8();
                 test[i].number = i+1;
                 test[i].state = (int)(Math.random()*6+1);
                 test[i].score = (int)(Math.random()*101+1);
                 test[i].state(test, 3);
             }
          } 
       }
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(5条)

报告相同问题?

问题事件

  • 系统已结题 4月6日
  • 已采纳回答 3月29日
  • 创建了问题 3月29日