السللام عليكم
الله يسعكم
وربي صراحه ربي يجزاكم خير الجزاء
امممم انا عندي سوال
Matrix Class – A class to manage matrices and add them. Create in the driver class two objects of it and use the add method.
هذا السوال انا سويته بس بكلاس وحده والمطلوب كلاسين ؟ كيف
import java.util.*;
class MatrixAddition {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i = 0; i < A.length; i++)
for (int j = 0; j < A.length; j++) {
A[j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i = 0; i < B.length; i++)
for (int j = 0; j < B.length; j++) {
B[j] = input.nextInt();
}
System.out.println("Matrix A: ");
for (int i = 0; i < A.length; i++) {
System.out.println();
for (int j = 0; j < A.length; j++) {
System.out.print(A[j] + " ");
}
}
System.out.println();
System.out.println();
System.out.println("Matrix B: ");
for (int i = 0; i < B.length; i++) {
System.out.println();
for (int j = 0; j < B.length; j++) {
System.out.print(B[j] + " ");
}
}
System.out.println();
System.out.println();
System.out.println("Addition Of Matrices: ");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
C[j] = A[j] + B[j];
System.out.print(C[j] + " ");
}
System.out.println();
}
}
}