Matrix Addition

Java Programming

Java Programming Examples

import java.io.*;

class addmatrix {

	/* Constructor */
	addmatrix(int a[ ][ ], int b[ ][ ]) {
		int ans[ ][ ] = new int[3][3];
		System.out.println("Matrix Addition");
		for(int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				ans[i][j]= a[i][j] + b[i][j];
				System.out.print(ans[i][j]+"\t");
			}
		}
	}
}

class matrix {
	public static void main(String args[ ]) {
		int a[ ][ ] = {{1,2,3},{4,5,6},{7,8,9}};
		int b[ ][ ] = {{4,4,4},{4,4,4},{4,4,4}};
		addmatrix addmat = new addmatrix(a, b);
	}
}


          /****** Output ******/
          

Matrix Addition


5 6 7


8 9 10


11 12 13

Learn more about Matrix Addition