m0_64462600 2021-12-14 22:24 采纳率: 100%
浏览 45
已结题

java实现随机数表报错

img


img

img

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-12-15 08:53
    关注

    RecordType [] r=new RecordType[10];是数组对象,你不能直接给其某个元素中的属性赋值,要先实例化数组中的某个元素。

    public class Sqlist {
        static class RecordType{
            int key;
            int otherwise;
        }
        RecordType [] r=new RecordType[10];
        int length=1;
    }
    
    public class Test{
        public static void main(String[] args) {
            Sqlist arr=new Sqlist();
            Sqlist.RecordType r=new Sqlist.RecordType();
            r.key=1;
            r.otherwise=2;
            arr.r[1]=r;
            System.out.println(arr.r[1].key);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月23日
  • 已采纳回答 12月15日
  • 创建了问题 12月14日