System.out.print("Enter email: ");
String mailId = sc.next();
boolean validMail = true;
while(x.hasNext() && validMail == true)
{
String a = x.next();
if(mailId.equals(a))
{
System.out.println("The mail id already exists!");
System.out.print("Enter email again: ");
mailId = sc.next();
String b = x.next();
if(!mailId.equals(b))
{
validMail = true;
}
String c = x.next();
if(mailId.equals(c))
{
validMail = false;
}
}
}
In this block of code i want the user to write a mail id and if the mail already exists in the text file it should ask the user to input a valid mail id. But in this case the program checks the validation only once and if an existing mail is printed twice then the program accepts it! Please help me on this...just suggests me a method where as i can ask the user a mail id and check if it is present in my text file if yes then ask one more until it is valid or else just let the program continue....