Bonjour,
j'essaye de faire un programme qui a pour but d'insérer des crochets dans un chaîne de caractère du type "pomme((carotte(radis)), chocolat(caramel))" je souhaite insérer un crochet ouvrant après la dernière parenthèse ouvrante et un crochet fermant avant la première parenthèse fermante, et cela pour chaque sous chaîne (avant la virgule) ce qui donnerai
"pomme((carotte([radis])), chocolat([caramel]))"

Pour cela j'ai écris ce petit programme en java, mais cela ne marche pas, aidez moi a trouver le problème merci
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
 
public class Main { 
 
public static void main(String[] args) { 
        // TODO code application logic here 
        String input=  "pomme((carotte(radis)), chocolat(caramel))"; 
        String[] sentences = input.split(","); 
        //String[] sent; 
 
   for (int i = 0; i < sentences.length; i++) { 
    int l=0; 
    char[] sentenceTab = sentences[i].toCharArray(); 
                                int leng=sentences.length+4; 
                                //String[] sent=sentences[leng]; 
                                char[] sentenceTab1 = sentences[leng].toCharArray(); 
 
    char c1=' '; 
 
               int k; 
    for(k =0; k < sentenceTab.length ; k++){ 
                                    for (l=0; l<sentenceTab1.length; l++) 
                                      { sentenceTab1[l]=sentenceTab[k]; 
                                    }} 
                                for (l=0; l<sentenceTab1.length+2; l++) 
                                {   c1=sentenceTab[l]; 
                                        if (c1==')'){ 
                                            int v = l ; 
                                            for (l=sentenceTab1.length+2; l>0; l--) 
                                            {   sentenceTab1[l]=sentenceTab1[l-1]; 
                                                } 
                                            sentenceTab1[v]=']'; 
 
                                } 
                                } 
                                for (l=sentenceTab1.length+2; l>0; l--) 
                                {char c = sentenceTab[l-1]; 
                                 if (c== '('){ 
                                     int j=c; 
                                     for (int v=sentenceTab1.length+2; v>0; v--) 
                                     { sentenceTab1[v]=sentenceTab1[v-1]; 
                                     } 
                                     sentenceTab1[j+1]='['; 
                                 } 
 
                                 } 
                                    sentences[i] = String.copyValueOf(sentenceTab1); 
 
                                } 
                        input = ""; 
   for (int i = 0; i < sentences.length-1; i++) { 
    input += sentences[i]+","; 
                        } 
 
                        input+=sentences[sentences.length-1]; 
                        System.out.println(input); 
    } 
}