If problem is in power, how to write it correctly?
This is because 1/3
is integer division, and it evaluates to 0
. You are effectively raising to the 0th power, which always yields 1. Try 1.0/3.0
instead.
Try Math.pow(long, 1D/3)
.
By default, numeric literals in Java are considered as ints. So, 1/3 is converted to 0 and not 0.33333 as should be the case. Qualifying it with 1D or 1F or 1.0 will solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With