-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.java
More file actions
60 lines (51 loc) · 1.48 KB
/
Matrix.java
File metadata and controls
60 lines (51 loc) · 1.48 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
import java.util.Scanner; // #include <iostream>
// DONE
public class Matrix
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
// array declaration
int [][] a = new int [2][3];
int [][] b = new int [2][3];
int [][] result = new int[2][3]; // resultant matrix
// storing data in first matrix
System.out.println("1ST"); // indicator
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3;j++)
{
System.out.print(" Enter Number at (" + i + "," + j + ") = ");
a[i][j] = obj.nextInt();
}
}
// storing data in second matrix
System.out.println("2nd"); // indicator
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3;j++)
{
System.out.print(" Enter Number at (" + i + "," + j + ") = ");
b[i][j] = obj.nextInt();
}
}
// multiplication
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3;j++)
{
result[i][j] = a[i][j] + b[i][j]; // sorry it was add not
// multiply
}
}
// OUTPUT
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3;j++)
{
System.out.print(result[i][j] + " ");
}
System.out.println(); // for spacing
}
}
}