The code inspects the chars in string invemail ("sammy99gmail.com"). notice how the email is missing the '@' sign, this program should tell if it's there or not, if so, print invemail "is a valid email" else invemail "is not valid".
The problem is that i get an error highlighted at 'emailfound' on the second 'if' statement. what am i doing wrong?
code:
String invemail = "sammy99gmail.com";
for (int i = 0; i < invemail.length(); i++)
{
char emailfind = invemail.charAt(i);
if (emailfind == '@')
{
boolean emailfound = true;
}
else
{
boolean enotfound = false;
}
}
if (emailfound = true)
{
System.out.println(invemail + "is a valid email");
}
else
{
System.out.println(invemail + "is invalid");
}
emailfound == trueor justif (emailfound)but instead you are assigningemailfound = trueand then checking istrueis still true.