Bonsoir,
Qu'est ce qu'il faut ajouter à mon code pour éliminer les résultats dupliqués suite aux lignes qui se répètent dans le fichier texte:
et le texte:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 import java.awt.List; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.*; public class Probabilité1 { public static void main (String [] args ) throws IOException { lecture("C:\\Users\\HP\\Desktop\\test-prob\\1.txt"); } public static void lecture (String string) { try { BufferedReader BF = new BufferedReader (new FileReader (string)); BufferedWriter fp = new BufferedWriter(new FileWriter("C:\\Users\\HP\\Desktop\\test-prob\\res.txt")); String ligne=""; String motF = ""; fp.flush(); while ( (ligne= BF.readLine())!=null ) { Tableaux t; if( ligne.contains("=")) { motF = ligne.substring(0, ligne.indexOf("=")); t=new Tableaux(); t.mots=ligne.substring(ligne.indexOf("="), ligne.length()).split(","); Double res=(double) t.mots.length; System.out.println(res); String out="P("+motF+")="+ (1/res); System.out.println(out); fp.append("P("+motF+")="+ (1/res)); fp.append("\n"); }//end if } fp.close(); } catch (Exception e){ System.out.println(e.toString());} }//end fct }//end class
merci de me donner un astuce pour pouvoir l'ajouter au codeet=although,and,connect,include,plus,together,whereas
en=across,at,during,in,inside,into,throughout,under,when,within,since
Allemagne=German,Germany,Germans
****
le=among,different,each,the,their,them,those
fast-food=Fast-Foods
au=during,even,however,in,on,over,within,at
Japon=Japan
Japon=Japan
au=during,even,however,in,on,over,within,at
au=during,even,however,in,on,over,within,at
Partager