If the length of user[]
and pass[]
is always equal, you can try this:
Update: This is much more simpler:
String currentUser = "empty";
boolean login=false;
for(int j = 0; j < user.length; j++){
if( username.equals(user[j]) && password.equals(pass[j])){
currentUser = user[j];
login=true;
break;
}
}
if(login)
System.out.println("Hello " + currentUser+ "!" );
else
System.out.println("Incorrect Login!" );
3
solved Creating Java nested FOR LOOPS and conditional statements without iterating over and over [closed]