I have the code bellow , which is for subtracting the 3D matrix from 2D.
Iam receiving error which is IndexOutOfBound
Code:
import java.util.*;
class test28{
public static void main ( String[] args ) {
int [][][] arr1 = {{{6,3,9,0},{8,6,5,3},{5, 4, 6, 7}}};
int [][] arr2= {{6,3,5,0},{8,6,5,3}};
test28 test = new test28();
System.out.println(Arrays.deepToString(test.subtract(arr1,arr2)));
}
public static int [][] subtract(int[][][] a, int[][] b) {
int[][] diff = new int[a[0].length][a[0][0].length];
for ( int j=0; j<a[0].length; j++){
for ( int k=0; k<a[0][0].length; k++){
diff[j][k] = a[0][j][k]- b[j][k];
}
}
return diff;
}
}
*************************************************************************************
Iam receiving error which is IndexOutOfBound
Last edited by a moderator: