forked from shikaruki/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SumOftwoArray.java
87 lines (50 loc) · 1.13 KB
/
SumOftwoArray.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Scanner;
public class SumOftwoArray {
private static void Display(int arr[])
{
for (int val : arr) {
System.out.println(val);
}
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int tcOne = scn.nextInt();
int arrOne[] = new int[tcOne];
for (int i = 0; i < arrOne.length; i++) {
arrOne[i] = scn.nextInt();
}
int tcTwo = scn.nextInt();
int arrTwo[] = new int[tcTwo];
for (int i = 0; i < arrTwo.length; i++) {
arrTwo[i] = scn.nextInt();
}
int arrSum[] = new int[tcOne>tcTwo?tcOne : tcTwo ];
int i = arrOne.length - 1;
int j = arrTwo.length - 1;
int k = arrSum.length - 1;
int c = 0;
while(k >= 0)
{
int d = c;
if(i >= 0)
{
d = d + arrOne[i];
}
if(j >= 0)
{
d = d + arrTwo[j];
}
c = c / 10;
d = d % 10;
arrSum[k] = d;
i--;
j--;
k--;
}
if(c!=0)
{
System.out.println(c);
}
Display(arrSum);
}
}