samedi 2 juin 2018

can't have the right return value in java method of boolean data type [duplicate]

This question already has an answer here:

Hello Guys i'am a newbie in programming, recently i was trying to make a simple app, and i wrote a method to return a boolean data, but i faced problem in returning the write value for data, it works only if the return value outside the other nested if condition, can anyone explain the right way to get the right value with this condition, and why this caused a problem!!
and is there anyway to improve my code structure !?

public boolean setEmail(String email) {
        if (email.endsWith(".com") && email.contains("@")) {
            if (email.contains("gmail") || email.contains("hotmail") || email.contains("icloud")) {
                this.email = email;
                return true;
            }
            //return true;
        } else {
            System.err.println("Please insert correct e-mail format{\"example@gmail.com\"}");
            return false;
        }
    }

Aucun commentaire:

Enregistrer un commentaire