-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsummat.java
More file actions
58 lines (57 loc) · 1.24 KB
/
summat.java
File metadata and controls
58 lines (57 loc) · 1.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
import java.io.*;
public class summat
{
public static void main(String args[])
{
int row=0, column=0,i ,j;
DataInputStream dis= new DataInputStream(System.in);
{
try
{
System.out.println("Enter the number of rows:");
row=Integer.parseInt(dis.readLine());
System.out.println("Enter the number of columns:");
column=Integer.parseInt(dis.readLine());
int a[][]=new int [row][column];
int b[][]=new int [row][column];
int c[][]=new int [row][column];
System.out.println(" Enter first matrix");
for(i=0;i<row;i++)
{
for( j=0;j<column;j++)
{
a[i][j]=Integer.parseInt(dis.readLine());
}
}
System.out.println("\n Enter Second matrix");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
b[i][j]=Integer.parseInt(dis.readLine());
}
}
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
c[i][j]=a[i][j]+b[i][j]; /*[addition]*/
/*c[i][j]=a[i][j]-b[i][j]; [subtraction] */
}
}
System.out.println ("Sum of the matrices are\n");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
catch(Exception e)
{
}
}
}
}