mardi 6 août 2019

if and else if won't work even when conditions are true [duplicate]

This question already has an answer here:

Unable to prompt if and else if. Only prompts else, even when if and/or else if is true

    while (true)
    {
        applicantStatus = applicantStatusScanner.next();
        //Method chaining to remove Uppercase/extra space
        if (applicantStatus.trim().toLowerCase() == "yes"){
            System.out.println("The rate will only be 15%");
            rate = 15;
            break;
        }
        else if (applicantStatus.trim().toLowerCase() == "no") {
            System.out.println("The rate will be 30%");
            rate = 30;
            break;
        }
        else {
            System.out.print("Please only type in 'Yes' or 'No' : ");
        }
        }

Loop should declare a break, if I type in "yes" or "no"

Aucun commentaire:

Enregistrer un commentaire