-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursion.java
More file actions
72 lines (50 loc) · 1.71 KB
/
Recursion.java
File metadata and controls
72 lines (50 loc) · 1.71 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
import fill_bag.Bag;
import fill_bag.Thing;
import pow.NegativePowException;
import pow.Pow;
public class Recursion {
public static void main(String[] args) {
// Test pow()
System.out.println("------ Test recursion pow ------");
System.out.println();
int x = 3;
int n1 = -3, n2 = 0, n3 = 3;
try {
System.out.println(String.format("pow(%d, %d) = %d", x, n1, Pow.pow(x, n1)));
} catch (NegativePowException e) {
System.out.println(e.getMessage());
}
try {
System.out.println(String.format("pow(%d, %d) = %d", x, n2, Pow.pow(x, n2)));
} catch (NegativePowException e) {
System.out.println(e.getMessage());
}
try {
System.out.println(String.format("pow(%d, %d) = %d", x, n3, Pow.pow(x, n3)));
} catch (NegativePowException e) {
System.out.println(e.getMessage());
}
System.out.println();
// Test placement()
System.out.println("------ Test recursion pow ------");
System.out.println();
Bag bag = new Bag(14);
Thing[] things = new Thing[]{
new Thing(5, 3),
new Thing(10, 5),
new Thing(6, 4),
new Thing(5, 2)
};
bag.fill(things);
System.out.println(bag);
Bag bag1 = new Bag(3);
bag1.fill(things);
System.out.println(bag1);
Bag bag2 = new Bag(5);
bag2.fill(things);
System.out.println(bag2);
Bag bag3 = new Bag(10);
bag3.fill(things);
System.out.println(bag3);
}
}