以下是公式
脂肪百分比= 495 /(1.0324 - 0.19077 x(LOG10(腰围))+ 0.15456 x(LOG10(身高))) - 450
以下是我的代码
import java.math.*;
public class Position
{
static double waist=66,neck=30,height=150;
public static void main(String[]args)
{
double fat = 495 / ( (1.0324 - 0.19077)* (Math.log(waist - neck)/Math.log(10)) + (0.15456) * (Math.log(height)/Math.log(10))) - 450;
System.out.println(fat);
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的答案是错误的.它应该是11.8%(使用以下http://lowcarbdiets.about.com/library/blbodyfatcalculator.htm)
我相信我在对数方面做错了.请帮助我得到正确的答案.
您已将其错误地写入代码.试试:
import java.math.*;
public class Position
{
static double waist=66,neck=30,height=150;
public static void main(String[]args)
{
double fat = 495 / ( 1.0324
- (0.19077 * (Math.log(waist - neck)/Math.log(10)))
+ (0.15456) * (Math.log(height)/Math.log(10))
) - 450;
System.out.println(fat);
}
}
Run Code Online (Sandbox Code Playgroud)
不同之处在于它没有1.0324 - 0.19077- 原始公式也没有,所以你的括号错了.
正如@a_horse_with_no_name所述,Math.log()将使用基于e的对数,而不是基于10的,但在此代码的范围内,结果是相同的.要使用基于10的,您将使用Math.log10().
| 归档时间: |
|
| 查看次数: |
17109 次 |
| 最近记录: |