# Calculating Sum of two Multidim

In this program we are going to make a simple program that will calculate the sum of the matrix.

Tutorials

# Sum of Multidimensional Arrays

In this program we are going to make a simple program that will calculate the sum of the matrix.

To make this program run we need to declare two multidimensional array of type int. Firstly calculate the length of the both the arrays. Now we need to make a matrix out of it. To make the matrix we will use the for loop. By making use of the for loop the rows and column will get divide. This process will be performed again for creating the second matrix.

After getting both the matrix with us we need to sum both the matrix. The both matrix will be added by using the for loop. The output will be displayed by using the println() method.

Here is the code of this program:

 ``` class MatrixSum{   public static void main(String[] args)  {   int array[][]= {{4,5,6},{6,8,9}};   int array1[][]= {{5,4,6},{5,6,7}};   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();   }   } }```

`Download this Example`

# Calculating Sum of two Multidim

Related Tutorials

Discuss: Calculating Sum of two Multidim   View All Comments

Subject (*):

joemari
September 13, 2011
multidimentionaL array

guys pls help me teach me how to make a program "multi dimentional array" and the user will be the one who will input numbers? **000 ***00 0***0 00*** 000** just Like the above. the "*" will be the user input and "0" is permanent. guys pls help me :((( guys pls help me :(
mhon
September 16, 2011
java

sample codes for java dimensional array!!!!
mahendra
August 7, 2012
addition of two 1d arrays in java

public class arrayAdd { public static void main(String[]args){ int[] array1 = {1,2,3}; int[] array2 = {4,5,6}; int[] array1and2 = new int[array1.length]; for(int i=0 ,j=0,k=0;i<=array1.length && j<=array2.length && k<=array1and2.length;i++,j++,k++){ array1and2[k]= array1[i]+array2[j]; System.out.println(array1and2[k]); } } }