gpt4 book ai didi

java - Java 中的除法总是结果为零 (0)?

转载 作者:搜寻专家 更新时间:2023-10-30 20:54:47 24 4
gpt4 key购买 nike

<分区>

下面的函数从 sharedpreferences、weight 和 height 获取两个值,我用它们来计算 BMI,当我打印值的内容时,我得到了我在 sharedprefs 中输入的值(这很好)但是当我对它们进行除法运算时,结果总是得到 0..哪里出错了?

public int computeBMI(){
SharedPreferences customSharedPreference = getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);

String Height = customSharedPreference.getString("heightpref", "");
String Weight = customSharedPreference.getString("weightpref", "");

int weight = Integer.parseInt(Weight);
int height = Integer.parseInt(Height);
Toast.makeText(CalculationsActivity.this, Height+" "+ Weight , Toast.LENGTH_LONG).show();

int bmi = weight/(height*height);
return bmi;

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com