Original Post
Having troubles with type conversions in Java.
I have a string containing some number, say, 12345, and I need to loop through the string, extracting a single digit at a time to perform operations on.
Here's what I have so far.
for(int i = 0; i < 10000; ++i) {
String temp = Integer.toString(i);
int sum = 0;
for(int n = 0; n < temp.length(); ++n) {
sum += Math.pow(Integer.parseInt(temp.charAt(n)), 4);
}
}
I tried doing this:
sum += Math.pow(Integer.parseInt(temp.charAt(n).toString()), 4);
but it didn't work, and as I have it right now, it won't let me parse a char, so I need to convert it to string somehow.
Thanks
I have a string containing some number, say, 12345, and I need to loop through the string, extracting a single digit at a time to perform operations on.
Here's what I have so far.
for(int i = 0; i < 10000; ++i) {
String temp = Integer.toString(i);
int sum = 0;
for(int n = 0; n < temp.length(); ++n) {
sum += Math.pow(Integer.parseInt(temp.charAt(n)), 4);
}
}
I tried doing this:
sum += Math.pow(Integer.parseInt(temp.charAt(n).toString()), 4);
but it didn't work, and as I have it right now, it won't let me parse a char, so I need to convert it to string somehow.
Thanks