Answer to Question #304101 in Java | JSP | JSF for afrah

Question #304101

Task 1: Username and Domain Name extraction [10 points]

Write a program that reads an email address from the keyboard. Assuming that the email address contains one at-sign (@) after the username, extract and print the username and the domain name of the email address.

 

Input: rayanas@oldwestbury.edu

 

Output:

Username: rayons

Domain name: oldwestbury.com

 

Task 2: Company name extraction from URL [10 points]

Write a program that reads a commercial website URL from the keyboard; you should expect that the URL starts with www, and ends with .com. Retrieve the name of the site, convert the first letter to uppercase to get the company name, and output it.

 

Input: www.yahoo.com

 

Output:

Company name: Yahoo

 

*use Scanner class to read a String as input from the keyboard for both the tasks. Check the following two lines of code for doing that.

 

Scanner scan = new Scanner(System.in);

String str = scan.next(); 



1
Expert's answer
2022-03-01T18:27:18-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Email:");
        String str = scan.next();
        String[] data = str.split("@");
        System.out.println("Username: " + data[0]);
        System.out.println("Domain name: " + data[1]);

        System.out.println("\nURL:");
        str = scan.next();
        data = str.split("\\.");
        System.out.println("Company name: " + data[1].substring(0, 1).toUpperCase() + data[1].substring(1));
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS