- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.java
More file actions
Latest commit
85 lines (84 loc) · 2.24 KB
/
Copy pathmatrix.java
File metadata and controls
85 lines (84 loc) · 2.24 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
importjava.util.*;
classmatrix
{
publicstaticvoidmain(Stringargs[])
{
Scannerscan=newScanner(System.in);
intr,c,i,j,r1,c1;
inta[][]=newint [50][50];
intb[][]=newint [50][50];
intd[][]=newint [50][50];
System.out.println("Enter the number of rows:");
r=scan.nextInt();
System.out.println("Enter the number of columns");
c=scan.nextInt();
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j]=scan.nextInt();
}
}
System.out.println("Matrix1");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println("\n");
}
System.out.println("Enter the number of rows of matrix 2:");
r1=scan.nextInt();
System.out.println("Enter the number of columns of matrix 2");
c1=scan.nextInt();
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
b[i][j]=scan.nextInt();
}
}
System.out.println("Matrix2");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println("\n");
}
System.out.println("SUM");
if(r==r1 && c==c1)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
d[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
System.out.print(d[i][j]+"\t");
}
System.out.println("\n");
}
System.out.println("Transpose");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
System.out.print(d[j][i]+"\t");
}
System.out.println("\n");
}
}
else
{
System.out.println("Addition not possible");
}
}
}