如果陈述不正常

时间:2014-09-17 05:20:07

标签: java

你好堆垛机,

      System.out.print("Enter your first name:  ");
  firstName = keyboard.nextLine();
  if(firstName!="Mike"&&firstName!="mike"&&firstName!="Diane"&&firstName!="diane")
  {
      System.out.println("derp");
  }
  else
      discount=true;

然而,这是结果:

Enter your first name:  diane
derp

如果有人能告诉我我做错了什么,那将非常非常感谢你!

1 个答案:

答案 0 :(得分:0)

public class Test{

    public static void main(String[] args) {

        System.out.print("Enter your first name:  ");
        Scanner keyboard = new Scanner(System.in);
        String firstName = keyboard.nextLine();
        if (!(firstName.equalsIgnoreCase("mike") || (firstName.equalsIgnoreCase("diane")))) {
            System.out.println("derp");
        } else
            System.out.println("true");
    }
}

<强>输出

Enter your first name:  diane
true