Challenge: Split an Email

Lab Java Beginner 10 points

Read an email address and print the user name and the domain on separate lines, then whether the domain ends with .com.

Input

One email address containing one @.

Output

User: <before @>
Domain: <after @>
Dot com: <true/false>

Example

Input

asha@vulntech.com

Output

User: asha
Domain: vulntech.com
Dot com: true
Sample input available Sample output available
Editor
Java

Hints

indexOf("@") finds the position of @.

substring(0, at) is everything before it, substring(at + 1) everything after.

endsWith(".com") gives true or false.

Solution explanation

Find the @ once, then cut the string into the part before and after it.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String email = sc.nextLine().trim();
        int at = email.indexOf("@");
        String domain = email.substring(at + 1);
        System.out.println("User: " + email.substring(0, at));
        System.out.println("Domain: " + domain);
        System.out.println("Dot com: " + domain.endsWith(".com"));
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD