Write a method, isEmailAddress, that is passed a String argument.

LANGUAGE: Java

CHALLENGE:

Write a method, isEmailAddress, that is passed a String argument.
It returns true or false depending on whether the argument has the form of an email address.
In this exercise, assume that an email address has one and only one “@” sign and no spaces, tabs or newline characters.

SOLUTION:

public static boolean isEmailAddress(String s)
{
    int space=0,dot=0,atTheRate=0;
    int i;
    for(i=0;i<s.length();i++)
    {
        if(s.charAt(i)==' ')space++;
        if(s.charAt(i)=='.')dot++;
        if(s.charAt(i)=='@')atTheRate++;
    }
    if(space==0 && dot>=1 && atTheRate==1)return true;
    else return false;
}