-
Notifications
You must be signed in to change notification settings - Fork 51
/
MATRIX_CALCULATOR.java
96 lines (85 loc) · 3.52 KB
/
MATRIX_CALCULATOR.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.util.Scanner;
public class JAVA_01 {
static void printInput( int [][]num,String matrix_num) {
System.out.println(matrix_num);
for (int i = 0; i <= num.length - 1; i++) {
for (int j = 0; j <= num[i].length - 1; j++) {
System.out.print(num[i][j]);
System.out.print(" ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] num1 = new int[3][3];
int[][] num2 = new int[3][3];
int[][] SUM = new int[3][3];
int[][] SUB = new int[3][3];
int[][] MUL = new int[3][3];
String first_mat = "YOUR FIRST MATRIX :";
String second_mat = "YOUR SECOND MATRIX :";
String Sum_print = "THE SUM OF THESE TWO MATRIX :";
String SuB_print = "THE SUBTRACTION OF THESE TWO MATRIX :";
String MUL_print = "THE MULTIPLICATION OF THESE TWO MATRIX :";
//WORKING PROCESS
while (true) {
System.out.println("<--------CHOOSE YOUR MATRIX OPERATION------>");
System.out.println("PRESS \n 1. FOR ADDITION \n 2. FOR SUBTRACTION \n 3. FOR MULTIPLICATION \n");
int operator = input.nextInt();
System.out.println("ENTER THE FIRST MATRIX :");
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
num1[i][j] = input.nextInt();
System.out.print(" ");
}
System.out.println();
}
System.out.println("ENTER THE SECOND MATRIX :");
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
num2[i][j] = input.nextInt();
System.out.print(" ");
}
System.out.println();
}
if(operator==1) {
// ADDITION OF THESE MATRIX
printInput(num1, first_mat);
printInput(num2, second_mat);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
SUM[i][j] = num1[i][j] + num2[i][j];
}
}
printInput(SUM, Sum_print);
} else if (operator==2) {
// SUBTRACTION OF THESE MATRIX
printInput(num1, first_mat);
printInput(num2, second_mat);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
SUB[i][j] = num1[i][j] - num2[i][j];
}
}
printInput(SUB, SuB_print);
} else if (operator==3) {
// MULTIPLICATION OF THESE MATRIX
printInput(num1, first_mat);
printInput(num2, second_mat);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++)
{
MUL[i][j]=0;
for(int k=0;k<=2;k++)
{
MUL[i][j]= MUL[i][j]+ num1[i][k] * num2[k][j] ;
}
}
}
printInput(MUL, MUL_print);
}
System.out.println();
}
}
}