CommencerCommencer gratuitement

Email checking

You want to check email addresses. As email addresses always have to contain at least one @ character and a . afterwards, you can check this with a two-part logical expression.

Cet exercice fait partie du cours

Intermediate Java

Afficher le cours

Instructions

  • Choose the correct logical operator to put in the logical expression.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

class EMailChecker {
  public static void main(String[] args) {
    String address = "[email protected]";
    int addLen = address.length();

    // Write the correct logical operator to make sure the address is valid
    if (address.contains("@") ____ address.charAt(addLen - 4) == '.') {
      System.out.println("Send that email !");
    } else {
      System.out.println("That's not a valid email");
    }
  }
}
Modifier et exécuter le code