Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Automatic typecasting during overlapping assignment (+=, *=, ...) :
sum += Math.pow();
Explicit type casting:
sum = sum + (int) Math.pow();
You are trying to declare an int variable with a double value, which obviously won't work.
However, in this case it works, because compilator knows that the type of sum variable is int and it just casts it to int. Since the result of pow is an integer (double), nothing special happens, but if the result were a non-integer, then the decimal part of the method's result would be truncated (100.18 would be 100, 11.254 would be 11, 1.0 would be 1, and so on, and so on...).
I know this comment is 7 months old, but I wanted to clear it up.
That is correct, why does this code work. It shouldn't at all.
e1 += e2 translates into e1 = (T) (e1 + e2), where T is a type of e1. In this case, the implicit cast crops double into int, which might lead to a not-very-easy-to-find bug:
int num = 1;
double d = 9999999999d;
num += d;
This comment is hidden because it contains spoiler information about the solution
https://stackoverflow.com/questions/2696812/varying-behavior-for-possible-loss-of-precision
https://stackoverflow.com/questions/8710619/why-dont-javas-compound-assignment-operators-require-casting
if you only want one statement run after the condition, the curly braces is not necessary