-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path8.java
More file actions
98 lines (96 loc) · 2.68 KB
/
8.java
File metadata and controls
98 lines (96 loc) · 2.68 KB
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
95
96
97
98
import java.util.*;
public class Main{
public void addition(int[][] a,int[][] b)
{
int i,j;
for(i=0;i<3;i++)
{
System.out.print("[ ");
for(j=0;j<3;j++)
{
System.out.print((a[i][j]+b[i][j])+" ");
}
System.out.println("]");
}
}
public void subtraction(int[][] a,int[][] b)
{
int i,j;
for(i=0;i<3;i++)
{
System.out.print("[ ");
for(j=0;j<3;j++)
{
System.out.print((a[i][j]-b[i][j])+" ");
}
System.out.println("]");
}
}
public void multiplication(int[][] a,int[][] b)
{
int i,j;
int sum=0;
for(i=0;i<3;i++)
{
System.out.print("[ ");
for(j=0;j<3;j++)
{
for(int k=0;k<3;k++)
{
sum+=(a[i][k]*b[k][j]);
}
System.out.print(sum+" ");
sum=0;
}
System.out.println("]");
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Main ob = new Main();
int i, j,ch;
int [][] a = new int[3][3];
int [][] b = new int[3][3];
System.out.println("Enter the values of a");
for (i = 0; i < 3; i++) {
System.out.print("[ ");
for (j = 0; j < 3; j++) {
a[i][j]=sc.nextInt();
}
}
System.out.println("Enter the values of b");
for (i = 0; i < 3; i++) {
System.out.print("[ ");
for (j = 0; j < 3; j++) {
b[i][j]=sc.nextInt();
}
}
while(true) {
System.out.println("|--------MENU--------|");
System.out.println("| 1.Addition |");
System.out.println("| 2.Subtraction |");
System.out.println("| 3.Multiplication |");
System.out.println("| 4.Exit |");
System.out.println("|--------------------|");
System.out.println("Enter your choice");
ch = sc.nextInt();
switch (ch) {
case 1:
ob.addition(a, b);
break;
case 2:
ob.subtraction(a, b);
break;
case 3:
ob.multiplication(a, b);
break;
case 4:
System.exit(0);
default:
System.out.println("Wrong choice glupy");
break;
}
}
}
}