Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #1 - java #6646

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Retos/Reto #1 - EL LENGUAJE HACKER [Fácil]/java/julian98789.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import java.util.Scanner;

public class lenguajeHaker {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Introduce el texto a traducir a lenguaje hacker (leet):");
String input = scanner.nextLine();

String textoLeet = traducirALeet(input);
System.out.println("Texto en lenguaje hacker: " + textoLeet);

scanner.close();
}

public static String traducirALeet(String texto) {
String[][] diccionarioLeet = {
{"a", "4"},
{"b", "8"},
{"c", "<"},
{"d", "d"},
{"e", "3"},
{"f", "f"},
{"g", "9"},
{"h", "#"},
{"i", "1"},
{"j", "j"},
{"k", "k"},
{"l", "1"},
{"m", "m"},
{"n", "n"},
{"o", "0"},
{"p", "p"},
{"q", "q"},
{"r", "2"},
{"s", "5"},
{"t", "7"},
{"u", "u"},
{"v", "v"},
{"w", "w"},
{"x", "x"},
{"y", "y"},
{"z", "2"},
{"0", "0"},
{"1", "1"},
{"2", "2"},
{"3", "3"},
{"4", "4"},
{"5", "5"},
{"6", "6"},
{"7", "7"},
{"8", "8"},
{"9", "9"}
};

StringBuilder traducido = new StringBuilder();

for (char ch : texto.toCharArray()) {
String charComoString = String.valueOf(ch).toLowerCase();
boolean encontrado = false;

for (String[] par : diccionarioLeet) {
if (par[0].equals(charComoString)) {
traducido.append(par[1]);
encontrado = true;
break;
}
}

if (!encontrado) {
traducido.append(ch);
}
}

return traducido.toString();
}
}