嗨我在修理单选按钮时遇到问题,我是编码和编写简单计算器的新手,但我不知道如何解决这个问题。
public void onClick(查看arg0){ // TODO自动生成的方法存根
float height=0;
float age = 0;
float weight=0;
float result=0;
height= Float.parseFloat(h.getText().toString());
age= Float.parseFloat(a.getText().toString());
weight= Float.parseFloat(w.getText().toString());
我的问题与if语句有关,这个等式是不正确的,因为它说它不能识别" *"我如何格式化方程式使其工作而不删除方程式如果他们是这个代码中的其他错误我会相应如果你能解决这个也谢谢你
if (male.isChecked()) {
result = (66.47 + (13.75 * w) + (5.0 * h) - (6.75 * a));
}
else if (female.isChecked()){
result = (665.09 + (9.56 * w) + (1.84 * h) - (4.67*a));
}
r.setText(String.valueOf(result));
答案 0 :(得分:0)
更改
result = (66.47 + (13.75 * w) + (5.0 * h) - (6.75 * a));
到
result = (66.47 + (13.75 * weight) + (5.0 * height) - (6.75 * age));
您无法在w
,h
或a
上应用乘法,因为它们是View
。
你需要获取它们的值然后执行乘法,