This commit is contained in:
James Boutaric
2025-10-15 10:26:53 +02:00
parent d074170b0f
commit c8a83e9637
8 changed files with 22969 additions and 0 deletions

28
word_search.java Normal file
View File

@@ -0,0 +1,28 @@
import java.util.*;
import java.io.*;
public class word_search {
public static String getRandomWord() {
List<String> words = new ArrayList<>(); // Liste dynamique de mots
Random random = new Random();
try { //lis le fichier, regarde si il existe avant de sélectionner un mot aléatoire
File file = new File("francais.txt");
Scanner scanner = new Scanner(file, "UTF-8");
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (!line.isEmpty()) { // ignore les lignes vides
words.add(line.toLowerCase());
}
}
scanner.close();
if (words.isEmpty()) {
System.out.println(" Aucun mot trouvé dans le fichier français.txt !");
return "erreur";
}
return words.get(random.nextInt(words.size()));
} catch (FileNotFoundException e) {
System.out.println(" Fichier 'français.txt' introuvable !");
return "erreur";
}
}
}