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