Get startedGet started for free

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.

This exercise is part of the course

Intermediate Java

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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");
    }
  }
}
Edit and Run Code