-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.java
More file actions
49 lines (45 loc) · 1.11 KB
/
Copy pathcheck.java
File metadata and controls
49 lines (45 loc) · 1.11 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
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class check {
public static void main(String[] args) {
int carry = 0;
List<Integer> A = new LinkedList<Integer>();
List<Integer> B = new LinkedList<Integer>();
List<Integer> C = new LinkedList<Integer>();
A.add(7);
A.add(8);
A.add(9);
A.add(3);
A.add(6);
B.add(4);
B.add(5);
B.add(3);
ListIterator<Integer> iterA = A.listIterator();
ListIterator<Integer> iterB = B.listIterator();
ListIterator<Integer> iterC = C.listIterator(C.size());
while (iterA.hasNext()) {
int n1 = iterA.next();
int n2 = 0;
if(iterB.hasNext()) {
n2 = iterB.next();
}
int result = n1+n2+carry;
if(result<10) {
C.add(result);
carry = 0;
}
else {
C.add(result%10);
carry = result/10;
}
}
if(carry>0) {
C.add(carry);
}
while (iterC.hasNext()) {
int n = iterC.next();
System.out.print(n);
}
}
}