Import [Link].
Scanner;
Public class Matrix {
Int m, n, i, j;
Int[][] matrix;
Public Matrix(int m, int n) {
This.m = m;
This.n = n;
[Link] = new int[m][n];
Public void InputMatrix(Scanner sc) {
[Link](“Nhap phan tu ma tran: “);
For (i = 0; i < m; i++) {
For (j = 0; j < n; j++) {
[Link](“Nhap a%d%d: “, i + 1, j + 1);
Matrix[i][j] = [Link]();
Public void PrintMatrix() {
For (i = 0; i < m; i++) {
For (j = 0; j < n; j++) {
[Link](“%d “, [Link][i][j]);
[Link](“\n”);
}
Public Matrix AddMatrix(Matrix other) {
If (this.m != other.m || this.n != other.n)
Throw new IllegalArgumentException(“Khong cong duoc 2 ma
tran.”);
Matrix res = new Matrix(m, n);
For (i = 0; i < m; i++) {
For (j = 0; j < n; j++) {
[Link][i][j] = [Link][i][j] + [Link][i][j];
Return res;
}
Public Matrix MinusMatrix(Matrix other) {
If (this.m != other.m || this.n != other.n)
Throw new IllegalArgumentException(“Khong tru duoc 2 ma
tran.”);
Matrix res = new Matrix(m, n);
For (i = 0; i < m; i++) {
For (j = 0; j < n; j++) {
[Link][i][j] = [Link][i][j] – [Link][i][j];
Return res;
}
Public Matrix MultiplyMatrix(Matrix other) {
If (this.n != other.m)
Throw new IllegalArgumentException(“Khong nhan duoc 2 ma
tran.”);
Matrix res = new Matrix(this.m, other.n);
For (int i = 0; i < this.m; i++) {
For (int j = 0; j < other.n; j++) {
Int sum = 0;
For (int k = 0; k < this.n; k++) {
Sum += [Link][i][k] * [Link][k][j];
}
[Link][i][j] = sum;
Return res;
Public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Matrix m1 = new Matrix(2, 2);
[Link](sc);
[Link]();
Matrix m2 = new Matrix(2, 2);
[Link](sc);
[Link]();
Matrix sum = [Link](m2);
[Link]();
Matrix diff = [Link](m2);
[Link]();
Matrix prod = [Link](m2);
[Link]();
[Link]();