शुरू करेंमुफ़्त में शुरू करें

ईमेल जाँच, लेकिन और बेहतर

लोग आपके ईमेल चेकर से इतने खुश हुए कि वे इसे और ज़रूरतों के अनुरूप बेहतर बनवाना चाहते हैं। आपको बताया गया कि सभी ईमेल 3 कैरेक्टर पर समाप्त नहीं होते, इसलिए उसे कोड में फिट करने की कोशिश करें। साथ ही, आपसे यह संदेश जोड़ने को कहा गया है जो बताए जब @ सिंबल गायब हो।

यह अभ्यास पाठ्यक्रम का हिस्सा है

इंटरमीडिएट Java

पाठ्यक्रम देखें

अभ्यास निर्देश

  • एक लॉजिकल ऑपरेटर जोड़ें ताकि यह जाँचा जा सके कि "@" के बाद कहीं भी "."" है या नहीं.
  • सही control flow का उपयोग करके सभी खराब ईमेल पकड़ें — आपको ऐसे ईमेल फ़्लैग करने हैं जिनमें दाईं ओर "@" हो या "@" के बाद "." न हो.
  • सही लॉजिकल ऑपरेटर का उपयोग करके सुनिश्चित करें कि जिन ईमेल में @ नहीं है, उनके लिए हमें एक संदेश मिले.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

class EMailChecker {
  public static void main(String[] args) {
    String adrs = "[email protected]";
    int addLen = adrs.length();
    boolean hasAt = adrs.contains("@");

    if (hasAt && adrs.charAt(addLen - 4) == '.') {
      System.out.println("Send that email !");
      // Enter the correct logical operator to be able to catch all correct emails
    } else if (hasAt && (adrs.charAt(addLen - 3) == '.' ____ hasDotAfterAt(adrs))) {
      System.out.println("That's a correct email address");
      // Use the correct keyword to catch any bad email addresses
    } ____ {
      // Make sure that the users know when the '@' is missing
      if (____hasAt) {
        System.out.println("Your email is missing the '@'");
      } else {
        System.out.println("That's not a valid email");
      }
    }
  }

  static boolean hasDotAfterAt(String address) {
    int atPos = address.indexOf('@');
    String subString = address.substring(atPos);
    return subString.contains(".");
  }
}
कोड संपादित करें और चलाएँ