-1

I'm trying to programme in android, but my if/else code is not working. Basically, its a quiz application that determines whether a person's answers are correct or not. But whatever the answer, the output is the output given in 'else'.

if(message=="panama canal"){
         Answer="Correct!";
    }
    else {
        Answer="Totally wrong";

    }
  • 1
    String comparision with equals() method..change like if(message.equals("panama canal"){ – kalyan pvs Jun 07 '14 at 12:15
  • `if(message=="panama canal"){` is **wrong**. Use `if(message.equals("panama canal")){` – Phantômaxx Jun 07 '14 at 12:15
  • Java's == operator check by reference, not by value (as .Net does) so the reference to the "panama canal" string constant is always different to any string you declare at runtime – Machinarius Jun 07 '14 at 12:16

1 Answers1

0

In Java you need to compare Strings with the equals method. As written you are comparing if the two are the same object.

Baldy
  • 2,002
  • 14
  • 14