How to match a string of array by if method. Means i take some value in a string array and take user input and then input match that string array is right or wrong if right give a value or wrong give other value.And I want to take input use it in loop. I have such a code and i do it without loop can match but can not use loop.
public class third {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
System.out.println("Enter a name:\n");
String first_name;
first_name=user_input.next();
String last_name;
last_name=user_input.next();
if(first_name.matches("Elory"))
{
System.out.println("MR. " + first_name + " " + last_name);
}
else if(first_name.matches("Fred"))
{
System.out.println("MR. "+ first_name+" "+last_name);
}
else if(first_name.matches("Graham"))
{
System.out.println("MR. "+ first_name+" "+last_name);
}
else if(first_name.matches("Amy"))
{
System.out.println("MS. "+ first_name+" "+last_name);
}
else if(first_name.matches("Buffy"))
{
System.out.println("MS. "+ first_name+" "+last_name);
}
else if(first_name.matches("Cathy"))
{
System.out.println("MS. "+ first_name+" "+last_name);
}
else
{
System.out.println(first_name+" "+last_name);
}
}
}