Matrix
Matrix
Scanner;
public class AdditonOfTwoMatrix
{
public static void main(String[] args)
{
Scanner scanner = new
Scanner(System.in);
System.out.print("Enter the number of rows in the matrices: ");
int rows = scanner.nextInt();
System.out.print("Enter the number of columns in the matrices: ");
int columns = scanner.nextInt();
int[][] matrix1 = new int[rows] [columns];
int[][] matrix2 = new int[rows] [columns];
int[][] resultMatrix = new int[rows] [columns];
System.out.println("Enter elements first matrix:");
for (int i = 0 ; i < rows; i++)
{
for (int j = 0 ; j < columns; j++)
{
System.out.print("Element [" + i + "][" + j + "]: ");
matrixl[i][j] = scanner.nextInt();
}
}
OUTPUT:
Enter the number of rows in the matrices: 4
Enter the number of colums in the matrices: 3
Enter elements of the first matrix:
Element [0][0]: 1
Element [0][1]: 2
Element [0][2]: 3
Element [1][0]: 4
Element [1][1]: 66
Element [1][2]: 77
Element [2][0]: 9
Element [2][1]: 4
Element [2][2]: 6
Element [3][0]: 7
Element [3][1]: 8
Element [3][2]: 22
Element [0][0]: 1
Element [0][1]: 4
Element [0][2]: 5
Element [1][0] 6
Element [1][1]: 77
Element [1][2]: 33
Element [2][0]: 99
Element [2][1]: 33
Element [2][2]: 55
Element [3][0]: 09
Element [3][1]: 99
Element [3][2]: 20
2 6 8
10 143 110
108 37 61
96 187 42