I wrote code for adding two matrices with the help of two-dimensional arrays. But after running, it is showing a result with error [[I@6acbcfc0
. If you know the meaning of [[I@6acbcfc0
, then please describe it as well. Following is the code:
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter dimensions: ");
int rows = sc.nextInt();
int cols = sc.nextInt();
int a[][] = new int [rows][cols];
int b[][] = new int [rows][cols];
System.out.println("Enter first matrix: ");
for (int i = 0; i<rows; i++) {
for (int j = 0; j<cols; j++) {
a[i][j] = sc.nextInt();
}
}
System.out.println("Enter second matrix: ");
for (int i = 0; i<rows; i++) {
for (int j = 0; j<cols; j++) {
b[i][j] = sc.nextInt();
}
}
int c [][] = new int [rows][cols];
for (int i = 0; i<rows; i++) {
for (int j = 0; j<cols; j++) {
c[i][j] = a[i][j] + b[i][j];
}
}
System.out.println("Result is " + c);
for(int i = 0; i<rows; i++) {
for (int j = 0; j<cols; j++) {
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}
and the output is
Enter dimensions:
2 2
Enter first matrix:
1 2
1 2
Enter second matrix:
1 2
1 2
Result is [[I@6acbcfc0
2 4
2 4
Please help me in removing "[[I@6acbcfc" and if you find any mistake in my code, please correct it so that i can understand it further better. Thank you.