我是一个初学java,我似乎无法弄清楚为什么字符串不会转换为布尔值。java字符串不能转换为布尔错误
错误代码特别出现在“if”行和“else if”行。
String Name, SystemOfMeasure;
Double Height, IdealWeight;
// Retrieve user data
Name = txtName.getText();
SystemOfMeasure = txtSystemOfMeasure.getText();
Height = Double.parseDouble(txtHeight.getText());
if (SystemOfMeasure = "M") {
IdealWeight = Height * Height * 25;
lblDisplay.setText(Name + ("'s ideal weight is") + IdealWeight);
} else if (SystemOfMeasure = "I") {
IdealWeight = Height * Height * 25/703;
lblDisplay.setText(Name + ("'s ideal weight is") + IdealWeight);
} else {
lblDisplay.setText("Please enter M or I");
}
太谢谢你了! –