Answer:
//This method takes a parameter called myString of type String
public static boolean isEmailAddress (String myString){
//verifying if the @ character exists in the string
if (myString.indexOf("@")!= -1)
{
//ensuring that only a single instance of @ appears in the string
if (myString.indexOf("@") == myString.lastIndexOf("@"))
{
//confirming absence of space characters
if (myString.indexOf(" ") == -1)
{
//checking for the absence of newline characters in the string
if (myString.indexOf("\n") == -1)
{
//checking for absence of tab characters in the string
if (myString.indexOf("\t") == -1)
{
return true;
}
}
}
}
}
return false;
}
Explanation:
The method takes a string presumed to be an email address and verifies whether it is valid, returning true if it is valid and false otherwise. The method checks the following conditions:
->The presence of the "@" character
->Only one occurrence of "@" exists in the string
->No spaces present
->No newline characters present
->No tab characters present
Returning true only if all these conditions are met.