java的不知道哪里出了问题ballball

import java.util.;
public class lj{
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
try{
int m=reader.nextInt();
int i=0,j=0;
int[][] a=new int[2
m][m];
int[][] b=new int[m][m];
for(i=0;i<b.length;i++){
b[i]=new int[i+1];}
for(i=0;i<2*m;i++){
for(j=0;j<m;j++){
a[i][j]=reader.nextInt();
}
}
for(i=0;i<m;i++){
for(j=0;j<m;j++){
b[i][j]=a[i][j]+a[i+m][j];
}
}
for(int[] row : b){
for(int col : row)
System.out.print(col+" ");
System.out.println();
}
}
catch(InputMismatchException e)
{
System.out.println("error input");
}
}
}

添加代码请用java代码块格式添加,不要直接复制,这样没法阅读代码

定义数组a的时候,应该是2*m不是2m

敢问这位仁兄要实现什么功能


public static void main(String args[]) {
        Scanner reader = new Scanner(System.in);
        try {
            int m = reader.nextInt();
            int i = 0, j = 0;
            int[][] a = new int[2 * m][m];
            int[][] b = new int[m][m];
            for (i = 0; i < 2 * m; i++) {
                for (j = 0; j < m; j++) {
                    a[i][j] = reader.nextInt();
                }
            }
            for (i = 0; i < m; i++) {
                for (j = 0; j < m; j++) {
                    b[i][j] = a[i][j] + a[i + m][j];
                }
            }
            for (int[] row : b) {
                for (int col : row) {
                    System.out.print(col + " ");
                }
                System.out.println();
            }
        } catch (InputMismatchException e) {
            System.out.println("error input");
        }
    }