m0_63853120 2023-04-02 23:18 采纳率: 66.7%
浏览 33
已结题

为什么the section cannt be launched


package recta;
public class rect1 {

   protected int row;

   protected int col;
   int a[][] = new int[row][col];

   public rect1(int row, int col) {
       this.row = row;
       this.col = col;
   }

   void show() {
       int i, j;
       for (i = 0; i < row; i++) {
           for (j = 0; j < col; j++)
               System.out.print(a[i][j]);
           System.out.println(" ");
       }
   }

   void construct() {
       int i, j;
       for (i = 0; i < row; i++)
           for (j = 0; j < col; j++)
               a[i][j] = (int) Math.random();
   }

   void addtogether() {
       int i, j;
       int sum = 0;
       for (i = 0; i < row; i++)
           for (j = 0; j < col; j++)
               sum = sum + a[i][j];
       System.out.println("所有元素和为:" + sum);

   }
}

class square extends rect1{
   public  square (int row,int col)
   { 
       super(row,col);
   }
   
   public void addline()
   {int i;
    int sum=0;
       for(i=0;i<row;i++)
           sum=a[i][i]+sum;
       System.out.println("主对角线的元素和为:"+sum);
   }
   
   public static void main(String args[])
   {
       square s=new square(6,6);
       s.construct();
       s.addline();
   }
}
   

为什么the section cannt be launched

  • 写回答

2条回答 默认 最新

  • Huazie 全栈领域优质创作者 2023-04-02 23:37
    关注

    二维数组 a 初始化 要放到构造方法里

        int a[][];
    
        public rect1(int row, int col) {
            this.row = row;
            this.col = col;
            a = new int[row][col];
        }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改