-
Notifications
You must be signed in to change notification settings - Fork 0
/
addmat.java
62 lines (56 loc) · 1.53 KB
/
addmat.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
import java.util.*;
class addmat
{
public static void main(String args[])
{
int a[][] = new int[10][10];
int b[][] = new int[10][10];
int c[][] = new int[10][10];
Scanner obj = new Scanner(System.in);
System.out.println("how many row in martix a");
int r1 = obj.nextInt();
System.out.println("how many coln in matrix a");
int c1 = obj.nextInt();
System.out.println("how many row in ");
int r2 = obj.nextInt();
System.out.println("how many coln");
int c2 = obj.nextInt();
if(r1==c2)
{
System.out.println("enter the elements into the array a");
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
a[i][j] = obj.nextInt();
System.out.println("enter the elements into the array b");
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
b[i][j] = obj.nextInt();
System.out.println("matrix a");
for(int i=0;i<r1;i++)
{
System.out.println();
for(int j=0;j<c1;j++)
System.out.print(a[i][j]+" ");
}
System.out.println("matrix b");
for(int i=0;i<r1;i++)
{
System.out.println();
for(int j=0;j<c1;j++)
System.out.print(b[i][j]+" ");
}
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
c[i][j] =a[i][j]+b[i][j];
System.out.println("matrix a+b");
for(int i=0;i<r1;i++)
{
System.out.println();
for(int j=0;j<c1;j++)
System.out.print(c[i][j]+" ");
}
}
else
System.out.println("add is not possible");
}
}