forked from menault/TD3_DEV51_Qualite_Algo
29 lines
766 B
Java
29 lines
766 B
Java
import java.io.*;
|
|
import java.util.*;
|
|
|
|
public class ChooseWord {
|
|
|
|
/*Fonction pour choisir le mot aléatoirement*/
|
|
public static String chooseTheWord() {
|
|
List<String> words = new ArrayList<>();
|
|
|
|
try (BufferedReader reader = new BufferedReader(new FileReader("motsFacile.txt"))) {
|
|
String line;
|
|
while ((line = reader.readLine()) != null) {
|
|
if (!line.trim().isEmpty()) {
|
|
words.add(line.trim().toLowerCase());
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (words.isEmpty()) {
|
|
return "default";
|
|
}
|
|
|
|
Random rand = new Random();
|
|
return words.get(rand.nextInt(words.size()));
|
|
}
|
|
}
|