Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an interactive Java program that asks a user for some text of interest an

ID: 3543671 • Letter: C

Question

Create an interactive Java program that asks a user for some text of interest and then displays the first email address found in that text. (This is the basis for one of the programs that spammers use to mine text, such as email messages, Web pages, and blogs, to find email addresses they can then add to their lists of people to spam.) For our purposes, an email address is composed of an "@" and the two maximal-length strings with no embedded whitespace surrounding that "@". If there is no email address in the text, then the program should display just an "@".

Construct the class EmailAddress.java.

Input text: Please send questions to me at email@tc.edu before noon today.

Extracted email address: email@tc.edu

Hint: I suggest you use the 'split' method of the String class. This method will divide a given string into tokens based on any dividing character you choose. For example, if you split an input sentence based on a space " ", you will get an array of words that you can process one at a time using a loop.

Explanation / Answer


mport java.util.Scanner;



public class EmailAddress {

public static void main(String args[])

{

System.out.println("Please enter the text line");

Scanner in=new Scanner(System.in);

String str=in.nextLine();

String[] str2=str.split(" ");

System.out.println("----------------------------------------");

System.out.println("Found Email id's in entered line");

for(int i=0;i<str2.length;i++)

{

if(str2[i].contains("@"))System.out.println(str2[i]);

}

  

  

}

  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote