| 
									
										
										
										
											2025-10-08 14:44:57 +02:00
										 |  |  | import java.util.*;
 | 
					
						
							|  |  |  | import java.io.*;
 | 
					
						
							| 
									
										
										
										
											2025-10-08 14:25:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | public class word_search {
 | 
					
						
							|  |  |  |     public static String getRandomWord() {
 | 
					
						
							| 
									
										
										
										
											2025-10-08 14:44:57 +02:00
										 |  |  |         List<String> words = new ArrayList<>(); // Liste dynamique de mots
 | 
					
						
							| 
									
										
										
										
											2025-10-08 14:25:38 +02:00
										 |  |  |         Random random = new Random();
 | 
					
						
							| 
									
										
										
										
											2025-10-08 14:44:57 +02:00
										 |  |  |         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";
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2025-10-08 14:25:38 +02:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2025-10-08 14:44:57 +02:00
										 |  |  | }
 |