-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProblem_092.java
More file actions
32 lines (24 loc) · 814 Bytes
/
Problem_092.java
File metadata and controls
32 lines (24 loc) · 814 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
package euler;
public class Problem_092 {
static int squareDigitChains() {
return squareDigitChains(10000000);
}
private static int squareDigitChains(int thresh) {
int count = 0;
for (int i = 1; i < thresh; i++) {
String next = digitSquareSum(Integer.toString(i));
while (!next.equals("1") && !next.equals("89")) {
next = digitSquareSum(next);
}
if (next.equals("89")) count++;
}
return count;
}
private static String digitSquareSum(String x) {
int sum = 0;
for (int i = 0; i < x.length(); i++) {
sum += (int) Math.pow(Integer.parseInt(x.substring(i, i+1)), 2);
}
return Integer.toString(sum);
}
}