Skip to content

Instantly share code, notes, and snippets.

@jeffersontpadua
Created December 3, 2018 20:09
Show Gist options
  • Save jeffersontpadua/d1be2b34d6b096758894ac686e4eb93e to your computer and use it in GitHub Desktop.
Save jeffersontpadua/d1be2b34d6b096758894ac686e4eb93e to your computer and use it in GitHub Desktop.
Força Bruta
import java.util.*;
class Main {
public static void main(String[] args) {
String palavra = "book";
List<Character> letras = new ArrayList<>();
for(char letra = 'a'; letra <= 'z'; letra++) {
letras.add(letra);
}
String teste = "";
int tentativas = 0;
while(!teste.equals(palavra)) {
int count = 0;
teste = "";
while(count < palavra.length()) {
teste += letras.get((int) Math.floor(Math.random() * 26));
}
tentativas++;
}
System.out.println("Palavra encontrada após: " + tentativas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment