当我打印消息的内容时,尽管displaybmi不小于19,但它始终使我“体重不足”
public String BMImessage(){
SharedPreferences customSharedPreference = getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
String Height = customSharedPreference.getString("heightpref", "");
String Weight = customSharedPreference.getString("weightpref", "");
float weight = Float.valueOf(Weight);
float height = Float.valueOf(Height);
float displaybmi = weight/(height*height);
if (displaybmi <19)
message = "Underweight" ;
else if (displaybmi >=19 && displaybmi <=25)
message = "Desirable Weight";
else if (displaybmi >=26 && displaybmi <=29)
message = "Overweight" ;
else if (displaybmi >=30 && displaybmi <=40)
message = "Obese";
else if (displaybmi >40)
message = "Extremely Obese" ;
return message;
}
最佳答案
还要仔细检查您的计算:
float displaybmi = weight/(height*height);
如果您的体重以千克为单位,而身高以米为单位,则此方法有效。如果您的体重以磅为单位,身高以英寸为单位,则需要添加转换系数:
float displaybmi = (weight * 703.0)/(height * height);
Calculate-Your-Body-Mass-Index