Java中的除法总是导致零(0)吗?
下面的函数从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;}
神不在的星期二
qq_笑_17
白猪掌柜的
繁星coding
随时随地看视频慕课网APP