mercredi 31 mars 2021

String isn't printing out the correct choice in an if else statement in java [duplicate]

        String pizzacrust;
        pizzacrust=JOptionPane.showInputDialog("What type of curst do yo want? (H)Hand-tossed, (T)Thin-crust, or (D)Deep-dish"
                + " (enter H,T, or D)");
        JOptionPane.showMessageDialog(null, "Your type of crust is " + pizzacrust);
        
String pizzacrustname = "Hand-tossed";
        if (pizzacrust == "H")
            pizzacrustname = "Hand-tossed";
        else if (pizzacrust == "T")
            pizzacrustname = "Thin-crust";
        else if (pizzacrust == "D")
            pizzacrustname = "Deep-dish";
        
        System.out.println(pizzacrustname);

The system will just print out "Hand-tossed" every time despite the choice being T or D

Aucun commentaire:

Enregistrer un commentaire