Comment

jhay^^,
How?,
June 27, 2008 at 6:54 PM

i tried this program on my jcreator i edited the code, i made it like this:

class MatrixSum
{
public static void main(String[] args)
{
int array[][]= {{1,3,2},{5,3,4},{3,4,5}};
int array1[][]= {{4,3,6},{5,6,2},{3,5,4}};

System.out.println("Number of Row= " + array.length);
System.out.println("Number of Column= " + array[1].length);
int l= array.length;
System.out.println("Matrix 1 : ");
for(int i = 0; i < l; i++) {
for(int j = 0; j <= l; j++) {
System.out.print(" "+ array[i][j]);
}
System.out.println();
}
int m= array1.length;
System.out.println("Matrix 2 : ");
for(int i = 0; i < m; i++) {
for(int j = 0; j <= m; j++) {
System.out.print(" "+array1[i][j]);
}
System.out.println();
}
System.out.println("Addition of both matrix : ");
for(int i = 0; i < m; i++) {
for(int j = 0; j <= m; j++) {
System.out.print(" "+(array[i][j]+array1[i][j]));
}
System.out.println();
}
}
}

In the lines 5 and 6 i added more numbers, and then compiled it, theres no error, but wen i run the prog this is the result:

----------------Configuration:
<Default>--------------------
Number of Row= 3
Number of Column= 3
Matrix 1 :
1 3 2Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at MatrixSum.main(matrix sum.java:15)

Process completed.