-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq30.java
More file actions
33 lines (30 loc) · 687 Bytes
/
q30.java
File metadata and controls
33 lines (30 loc) · 687 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
import java.math.*;
import java.util.*;
public class q30 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int result = 0;
for(int i = 10; i < 1000000; ++i){
if( i == digitsPower(i, 5)){
System.out.println("i: " + i);
result += i;
}
}
System.out.println("Sum: " + result);
}
public static int digitsPower(int x, int y){
//returns the sum of the digits of x, raised to the power of y
ArrayList<Integer> digits = new ArrayList<Integer>();
int i = 0;
while(x > 0){
digits.add(x % 10);
++i;
x = x/10;
}
i = 0;
for(int j = 0; j < digits.size(); ++j){
i += Math.pow(digits.get(j), y);
}
return i;
}
}