Raising number to fractional power java [duplicate]

心不动则不痛 提交于 2019-12-01 17:34:11

问题


I used the following code:

double pow = 3/7;

double num = 85;

System.out.println(Math.pow(num, pow));

Expected result:

6.71...

The output is

1.0

Any idea why?


回答1:


3/7 is evaluated to 0, since you are dividing two integers, so Math.pow(num, pow) becomes Math.pow(num, 0.0) which is 1.0.

Change it to 3.0/7 in order to get a floating point result.



来源:https://stackoverflow.com/questions/29877030/raising-number-to-fractional-power-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!