-1
int[][] A = {{11, 7},{-20,-22}};
int[][] B = {{A[0].length},{A.length}};
for(int i = 0; i < A.length;i ++){
for(int j = 0; j < A[0].length;j ++){
System.out.print(A[i][j] + "\t");
}
System.out.println();
}
for(int i = 0; i < A.length;i ++){
for(int j = 0; j < A[0].length;j ++){
B[i][j] = A[j][i];
}
}
The mistake is this :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at j.pkg1.J1.ex31(J1.java:132) C:\*******************************\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)
The line 132 is B[i][j] = A[j][i];
Our official language is Português. Translate your question.
– user28595
The index
A[j][i]
of array, there is no.– Valdeir Psr
I’m transposing A into B
– Rui Duarte
Do you know how to do a table test? https://answall.com/q/220474/5878. If the error is in row 132, while the example has not 20 lines, the error does not occur in this code. You probably tried to create a [mcve], which is good practice when asking, but the example does not reproduce the error.
– Woss
In the code that gave the error, the matrix is not square, correct?
– Woss