Explicitly cast result of Math.pow
to long
in Armstrong
(#4972)
This commit is contained in:
parent
f8de290188
commit
fc21a8bffe
@ -27,7 +27,7 @@ public class Armstrong {
|
|||||||
|
|
||||||
while (originalNumber > 0) {
|
while (originalNumber > 0) {
|
||||||
long digit = originalNumber % 10;
|
long digit = originalNumber % 10;
|
||||||
sum += Math.pow(digit, power); // The digit raised to the power of the number of digits and added to the sum.
|
sum += (long) Math.pow(digit, power); // The digit raised to the power of the number of digits and added to the sum.
|
||||||
originalNumber /= 10;
|
originalNumber /= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user