Created
December 3, 2018 20:09
-
-
Save jeffersontpadua/d1be2b34d6b096758894ac686e4eb93e to your computer and use it in GitHub Desktop.
Força Bruta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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