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