- Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathSumOftwoArray.java
More file actions
Latest commit
87 lines (50 loc) · 1.13 KB
/
Copy pathSumOftwoArray.java
File metadata and controls
87 lines (50 loc) · 1.13 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
86
87
importjava.util.Scanner;
publicclassSumOftwoArray {
privatestaticvoidDisplay(intarr[])
{
for (intval : arr) {
System.out.println(val);
}
}
publicstaticvoidmain(String[] args) {
Scannerscn = newScanner(System.in);
inttcOne = scn.nextInt();
intarrOne[] = newint[tcOne];
for (inti = 0; i < arrOne.length; i++) {
arrOne[i] = scn.nextInt();
}
inttcTwo = scn.nextInt();
intarrTwo[] = newint[tcTwo];
for (inti = 0; i < arrTwo.length; i++) {
arrTwo[i] = scn.nextInt();
}
intarrSum[] = newint[tcOne>tcTwo?tcOne : tcTwo ];
inti = arrOne.length - 1;
intj = arrTwo.length - 1;
intk = arrSum.length - 1;
intc = 0;
while(k >= 0)
{
intd = 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);
}
}