Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 7, 2020 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/28780e4d5b70ead025aed744a5db8b37 to your computer and use it in GitHub Desktop.
Save parzibyte/28780e4d5b70ead025aed744a5db8b37 to your computer and use it in GitHub Desktop.
private static String obtenerPistas(String suposicionPassword, String passwordCorrecto) {
String pistas = "";
for (int x = 0; x < suposicionPassword.length(); x++) {
// Si está en el lugar correcto se indica con un *
if (suposicionPassword.charAt(x) == passwordCorrecto.charAt(x)) {
pistas += "*";
continue;
}
// Si está en la cadena pero no en el lugar correcto, se indica con un _
int indiceCaracter = passwordCorrecto.indexOf(suposicionPassword.charAt(x));
if (indiceCaracter != -1) {
pistas += "_";
continue;
}
// Finalmente, si ninguna de las condiciones de arriba se cumple, el carácter no
// está
pistas += " ";
}
return pistas;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment