開始使用免費開始

Email 檢查

你想要檢查電子郵件地址。因為電子郵件地址一定要至少包含一個 @ 字元,且之後還要有一個 .,你可以用一個由兩部分組成的邏輯運算式來檢查。

本練習屬於課程

Java 中級

檢視課程

練習說明

  • 在邏輯運算式中,選擇正確的邏輯運算子。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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");
    }
  }
}
編輯並執行程式碼