class Program {
static String[] listaUsuarios
= new String[] { "1",
"12",
"123" }; System.
out.
println(autentica
("123")); System.
out.
println(autentica
("456")); }
public static boolean autentica
(String usuario
) { for(int i = 0; i < listaUsuarios.length; i++) {
if(usuario.equals(listaUsuarios[i])) {
return true;
}
}
//opcionalmente faz alguma coisa aqui.
return false;
}
}
//https://pt.stackoverflow.com/q/48512/101
Y2xhc3MgUHJvZ3JhbSB7CglzdGF0aWMgU3RyaW5nW10gbGlzdGFVc3VhcmlvcyA9IG5ldyBTdHJpbmdbXSB7ICIxIiwgIjEyIiwgIjEyMyIgfTsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbiB7CgkJU3lzdGVtLm91dC5wcmludGxuKGF1dGVudGljYSgiMTIzIikpOwoJCVN5c3RlbS5vdXQucHJpbnRsbihhdXRlbnRpY2EoIjQ1NiIpKTsKCX0KCXB1YmxpYyBzdGF0aWMgYm9vbGVhbiBhdXRlbnRpY2EgKFN0cmluZyB1c3VhcmlvKSB7CgkgICAgZm9yKGludCBpID0gMDsgaSA8IGxpc3RhVXN1YXJpb3MubGVuZ3RoOyBpKyspIHsKICAgIAkgICAgaWYodXN1YXJpby5lcXVhbHMobGlzdGFVc3Vhcmlvc1tpXSkpIHsKICAgICAgICAJICAgIHJldHVybiB0cnVlOwogICAgICAgIAl9CiAgICAJfQogICAgCS8vb3BjaW9uYWxtZW50ZSBmYXogYWxndW1hIGNvaXNhIGFxdWkuCiAgICAJcmV0dXJuIGZhbHNlOwoJfQp9CgovL2h0dHBzOi8vcHQuc3RhY2tvdmVyZmxvdy5jb20vcS80ODUxMi8xMDE=