String x = "[email protected]" // <--- it's .com
if (!x.trim().toUpperCase().endsWith(".COM"))
{
System.out.println("Your E-mail is missing a \".com\"");
}
else
{
System.out.println("Welcome, " + x);
}
和它的工作完美的罰款
但是當我嘗試包括與另一說法||運營商,那麼它根本不會
String x = "[email protected]"; // <--- now it's .edu
if (!x.trim().toUpperCase().endsWith(".COM") || !x.trim().toUpperCase().endsWith(".EDU"))
{
System.out.println("Your E-mail is missing a \".com\"");
}
else
{
System.out.println("Welcome, " + x);
}
自從我包括
|| !x.trim().toUpperCase().endsWith(".EDU");
在
if語句,我不斷收到我打印出來
因爲這兩個條件是互相排斥的。該檢查總是如此,因爲您的電子郵件永遠不會以''.COM''和''.EDU'結尾。 – f1sh
這裏有個合乎邏輯的問題。 – AxelH
'||'是或,你想要什麼,哪個是'&&' – niceman