mercredi 20 mai 2015

use Scanner to read a String with if/else statement

my intention is to let the user decide which method to use.

i have the following code:

try {
        String test = scan.next();
        if(test == "y") {
            //do stuff

        }
        else if (test == "n") {
            //do stuff
        }
    } catch (Exception e) {
        System.out.println("false");
    } 

I tried to analyze with the debugger. It is not jumping in the if-statement. can you help me out here?

Aucun commentaire:

Enregistrer un commentaire