-
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy path_2DArray.java
More file actions
54 lines (46 loc) · 1.31 KB
/
_2DArray.java
File metadata and controls
54 lines (46 loc) · 1.31 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
// package JAVA;
import java.util.Scanner;
public class _2DArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of Rows");
int rows = sc.nextInt();
System.out.println("Enter the number of Columns");
int cols = sc.nextInt();
int a[][] = new int[rows][cols];
int b[][] = new int[rows][cols];
System.out.println("Enter the elements of array A");
for (int i=0;i<rows;i++)
{
for (int j=0;j<cols;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("Enter the elements of array B");
for (int i=0;i<rows;i++)
{
for (int j=0;j<cols;j++)
{
b[i][j]=sc.nextInt();
}
}
int c[][] = new int[rows][cols];
for (int i=0;i<rows;i++)
{
for (int j=0;j<cols;j++)
{
c[i][j]=a[i][j]*b[i][j];
}
}
System.out.println("The sum of array A and B is :");
for (int i=0;i<rows;i++)
{
for (int j=0;j<cols;j++)
{
System.out.print(c[i][j]+" ");
}System.out.println();
}
sc.close();
}
}