mardi 31 août 2021

If / Statements with Strings (Java). No matter the method I try, It would say that the If statement is true when its not [duplicate]

There was code before this but to explain the section I'm having troubles with I cut out the rest. I've also tried an if/then else statement and it still didn't work.

    String fav_lang;
    System.out.println("\nEnough about me. What's your favourite language? (just don't say Python)");
    fav_lang = scan.next ( ); 

    String p = new String ("python");
    //add new a line here.
    if (fav_lang == p) {
        System.out.println("\nWow, that sucks, you should seek help.");
    }
    if (fav_lang != p) {
        System.out.println( "\n"+ fav_lang + ", that's great! Nice chatting with you " + full_name + ". I have to log off now. See ya!");
    }

Aucun commentaire:

Enregistrer un commentaire