Salut à tous.

Sujet : Créer une fonction qui lit une chaîne de caractère de type xxxNxxx avec N un nombre qui indique qu'on va copier, dans la chaîne, N-1 le caractère qui précède ce nombre.

Ma solution :
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
    public static String expandNumber(String input){
        /*Recherche du nombre*/
        int deb = 0, fin = 0, i=0, exp = 1, dim = input.length();
        ArrayList<Integer> nb = new ArrayList<Integer>();
        while((i < dim-1)){
 
            if((isInteger(input.substring(i,i+1)))&&(deb == 0)){
                fin = deb = i;
                nb.add(Integer.parseInt(input.substring(i,i+1)));
            }
 
            if((isInteger(input.substring(i,i+1)))&&(deb == 1)){
                fin = i;
                nb.add(Integer.parseInt(input.substring(i,i+1)));
            }
 
            i++;
        }
 
        if(i == dim-2){return "LOL y'a pas de nombre dans la chaine";}
 
 
        else{
 
        /*Couper autour du nombre*/
        String begin = new String(input.substring(0,deb-1));
        String end = new String(input.substring(fin+1,dim));
 
        /*Traitement*/
        int dim_nb = nb.size(); 
        int repet = nb.get(dim_nb -1);
 
        for (i = dim_nb-2 ; i > - 1; i--){
            repet = nb.get(i)*puiss(10,exp);
            exp+=1;
        } 
 
        String lol = input.substring(deb-1,deb);
        i=0;
        String temp = lol;
        while(i<repet-1){
            temp = temp.concat(lol);
            i+=1;
        }
 
        return begin.concat(temp).concat(end);
        }
    }
Question : Je suis débutant en programmation objet, pouvez vous me donner des méthodes orientées objet pour améliorer ma solution ?

Remarque : Ma solution ne marche pas si je met un nombre à la première place, je remarque, je vais modifier ça .