-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPuzzle4.java
More file actions
43 lines (33 loc) · 761 Bytes
/
Puzzle4.java
File metadata and controls
43 lines (33 loc) · 761 Bytes
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
class Puzzle4b {
private int ivar;
public void setIvar(int n) {
ivar = n;
}
public int doStuff(int factor) {
if (ivar > 100) {
return ivar * factor;
} else {
return ivar * (5 - factor);
}
}
}
public class Puzzle4 {
public static void main(String[] args) {
Puzzle4b[] obs = new Puzzle4b[6];
int y = 1;
int x = 0;
int result = 0;
while (x < 6) {
obs[x] = new Puzzle4b();
obs[x].setIvar(y);
y *= 10;
x += 1;
}
x = 6;
while (x > 0) {
x -= 1;
result += obs[x].doStuff(x);
}
System.out.println("result: " + result);
}
}