-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem112.java
More file actions
46 lines (46 loc) · 1.26 KB
/
Problem112.java
File metadata and controls
46 lines (46 loc) · 1.26 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
public class Problem112 {
private static boolean isDecr(int i) {
String[] nums = String.valueOf(i).split("");
for (int j = 1; j < nums.length; j++) {
if (Integer.parseInt(nums[j]) > Integer.parseInt(nums[j - 1])) {
return false;
}
}
return true;
}
private static boolean isIncr(int i) {
String[] nums = String.valueOf(i).split("");
for (int j = 1; j < nums.length; j++) {
if (Integer.parseInt(nums[j]) < Integer.parseInt(nums[j - 1])) {
return false;
}
}
return true;
}
private static boolean isBouncy(int i) {
if (isIncr(i)) {
return false;
}
if (isDecr(i)) {
return false;
}
return true;
}
public static void main(String[] args) {
int bouncy = 0;
int nonBouncy = 0;
int i = 1;
while (((double) bouncy) / (nonBouncy + bouncy) != .99) {
if (isBouncy(i)) {
bouncy++;
}
else {
nonBouncy++;
}
if (((double) bouncy) / (nonBouncy + bouncy) == .99) {
System.out.println(i);
}
i++;
}
}
}