0
我在下面的代码的if语句中遇到问题。 即使条件正确,我也无法登录if语句。我的语法正确吗?Selenium的Java - 字符串比较
String NicotineProduct="Not in the last 5 years"
if (NicotineProduct=="No, Never"||NicotineProduct=="Not in the last 5 years"||NicotineProduct=="Not in the last 3 years")
{
if (rateclass=="Pref Best No Nicotine")
rateclassval=1;
else if (rateclass=="Pref No Nicotine")
rateclassval=2;
else if (rateclass=="Select No Nicotine")
rateclassval=3;
else if (rateclass=="Standard No Nicotine")
rateclassval=4;
}
不,你的语法不正确,因为它没有显示你想要的语义。对于字符串比较,始终使用[String.equals()](http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#equals%28java.lang.Object%29);一切都意味着要求麻烦。 – JimmyB 2014-10-10 13:59:09