vendredi 1 avril 2016

Java Scanner String Input If statement [duplicate]

This question already has an answer here:

I am very new to Java, the program does not work. Here is part of my codes:

Scanner in = new Scanner(System.in);

  System.out.println(questions[0][0]);
  String s = in.nextLine();

  if (s == (names[1][0])) {
        System.out.println("Good, you are correct!");
  }
  else {
        System.out.println("Wrong answer, it is");
        System.out.println(questions[1][0]);
  }

When I entered the correct answer, it still prints out "Wrong answer, it is (questions[1][0])". Is the if else statement wrong? Or something else? Please help!

Aucun commentaire:

Enregistrer un commentaire