Skip to content

Commit 0f45150

Browse files
committed
feat: Extract and validate email components (username and domain)
🧠 Logic: - Given a string in email format, extract username using `substring(0, indexOf('@'))`. - Extract domain using `substring(indexOf('@') + 1, end of string)`. - Check if domain starts with "Gmail" and extract actual domain name (before '.') to validate. - Used `equalsIgnoreCase("gmail")` for case-insensitive comparison. Signed-off-by: Somesh diwan <[email protected]>
1 parent 52b19bb commit 0f45150

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

Section9ArrayAB/Array 2.0/src/StudentChallengeAB.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
public class StudentChallengeAB {
22
public static void main(String[] args) {
3-
43
String str = "[email protected]";
54

65
int i = str.indexOf("@");
7-
86
String uname = str.substring(0 , i);
9-
107
String domainname = str.substring(i+1, str.length());
118

129
System.out.println("UserName : " + uname);
13-
1410
System.out.println("Domain is: " + domainname);
15-
1611
System.out.println(domainname.startsWith("Gmail")); //Check Valid Gmail or not.
1712

18-
//Now we have to check whether this is domain name and gmail name is valid or not
19-
13+
//Now we have to check whether this is a domain name and gmail name is valid or not
2014
int j =domainname.indexOf(".");
2115
String name = domainname.substring(0, j);
2216
System.out.println(name.equalsIgnoreCase("gmail"));

0 commit comments

Comments
 (0)