I have a problem in this program where when I enter a correct value it gives me the correct output but it also asks me to enter my name again. It is working for when i enter an incorrect value 3 times it will terminate the program although it does not print out the error message. I am not sure how to change it so that it will only output the you are verified you may use the lift.
import java.util.Scanner;
public class Username
{
public static void main (String[]args)
{
Scanner kb = new Scanner (System.in);
// array containing usernames
String [] name = {"barry", "matty", "olly","joey"}; // elements in array
boolean x;
x = false;
int j = 0;
while (j < 3)
{
System.out.println("Enter your name");
String name1 = kb.nextLine();
boolean b = true;
for (int i = 0; i < name.length; i++) {
if (name[i].equals(name1))
{
System.out.println("you are verified you may use the lift");
x = true;
break;// to stop loop checking names
}
}
if (x = false)
{
System.out.println("wrong");
}
j++;
}
if(x = false)
{
System.out.println("Wrong password entered three times. goodbye.");
}
}}