Bonjour,
je veux faire la combinaisons deux à deux entre les mots qui ne sont pas dans la même ligne :
le ficher d'entré sera de cette manière:
a,an,
letter,
trap,bomb,
le résultat désirée sera:
a,letter
a,trap
a,bomb
an,letter
an,trap
an,bomb
letter,trap
letter,bomb
j'ai essayé d'exploiter les méthodes récursives mais j'ai pas réussie de les bien utliser
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package CoupleOccurrence;
 
import java.io.*;
import java.util.Vector;
 
public class CoupleCombAutresMethode {
 
	static String chaine="";
	static Vector<Tableaux> liste =new Vector<Tableaux>();
 
	public static void main(String[] args){
 
		final File folder = new File("C:\\Users\\HP\\Desktop\\Mots-Simples\\CouplesCombinaisons\\test_in");
		File[] listOfFiles = folder.listFiles();
		for (int i = 0; i < listOfFiles.length; i++) {
			    File fileEntry = listOfFiles[i];
			    System.out.println("***"+fileEntry);
			    String name = fileEntry.toString();
	 			  while(name.toString().contains("\\")){
	 				  name = name.substring(name.indexOf("\\")+1, name.length());
	 			  }
	 		   String nomFichier = "C:\\Users\\HP\\Desktop\\Mots-Simples\\CouplesCombinaisons\\test_out\\"+name;
		lecture(fileEntry,liste); 
		boucle(nomFichier,0);
		}
 
 
	}
 
 
	public static void lecture (File fichier,Vector<Tableaux>liste){
		String chaine="";
		Tableaux t;
		try{
 
		 	InputStream ips=new FileInputStream(fichier); 
			InputStreamReader ipsr=new InputStreamReader(ips);
			BufferedReader br=new BufferedReader(ipsr);
			String ligne;
			liste.clear();
			while ((ligne=br.readLine())!=null ){
			//	System.out.println(ligne);
				//chaine+=ligne+"\n";
				t=new Tableaux();
				t.mots=ligne.split(",");
				//System.out.println(t.mots.length);
				liste.add(t);
 
			}
 
			System.out.println("*************************");		
			br.close(); 
 
		}		
		catch (Exception e){
			System.out.println(e.toString());
		}
 
 
  }
 
	public static void boucle(String out, int i){
		try{
			OutputStream ips=new FileOutputStream(out,true); 
			OutputStreamWriter ipsr=new OutputStreamWriter(ips);
			BufferedWriter fp=new BufferedWriter(ipsr);
		//fp.flush();	
		if(i==liste.size()){
 
			//System.out.println("**"+chaine);
			//fp.append(chaine);
			//fp.append("\n");
 
		}
		else{
			for(int j=0;j<liste.get(i).mots.length;j++){
 
				System.out.println(	chaine=chaine+liste.get(i).mots[j]+",");
				//chaine=chaine+liste.get(i).mots[j]+",";
				boucle(out,i+1);
				//System.out.println(	chaine=chaine.substring(0,chaine.length()-liste.get(i).mots[j].length()-1));
			  chaine=chaine.substring(0,chaine.length()-liste.get(i).mots[j].length()-1);
			  boucle(out,i+1);
 
 
			}
 
		}
 
		//fp.close();
 
		}
		catch (Exception e){
			System.out.println(e.toString());
		}
	}
 
}
le résultat de mon code affiche:
a,
a,letter,
a,letter,trap,
a,letter,bomb,
a,trap,
a,bomb,
letter,
letter,trap,
letter,bomb,
trap,
bomb,
an,
an,letter,
an,letter,trap,
an,letter,bomb,
an,trap,
an,bomb,
letter,
letter,trap,
letter,bomb,
trap,
bomb,
j'arrive pas à corriger la bêtise que j'ai fait
est-ce que l'idée est faute et je doit refaire le code??