Bonjour tout le monde,

Je suis tout nouveau sur ce forum et je commence à apprendre java...

J'ai besoin de votre aide pour terminer un programme que je n'arrive pas à faire fonctionner:

Le programme
Il demande à l'utilisateur d’entrer une combinaison de 5 chiffres (combinaison 1) puis d'entrer une autre combinaison de 5 chiffres (combinaison 2).
La combinaison 2 doit correspondre à la combinaison 1. Donc, le programme affichera le nombre de bons chiffres.
Exemples:
1 /
combinaison 1 = 17678
combinaison 2 = 23733
nombre de bons chiffres = 1 (même s'il y a deux 7 dans la combinaison 1, l'utilisateur n'en a entré qu'un seul)
2 /
combinaison 1 = 84452
combinaison 2 = 13858
nombre de bons chiffres = 2
3/
combinaison 1 = 64321
combinaison 2 = 66666
nombre de bons chiffres = 1

Mon programme, QUI NE FONCTIONNE PAS, donne ça pour le moment :
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
public static void main (String[] params) {   
        int res = 0;
        String comb1;
        String comb2;
 
        System.out.println("combinaison 1 : ");
        comb1 = Clavier.lireString();
        System.out.println("combinaison 2 : ");
        comb2 = Clavier.lireString();
 
        for(int j = 0; j < comb1.length(); j++) {
            for(int i = 0; i < comb2.length(); i++) {
                if (comb1.charAt(j) == comb2.charAt(i)) {
                    res = res + 1;
                    if(i < comb2.length()) {
                        comb2 = comb2.substring(i);                        
                    }else{
                        comb2= comb2.substring(i+1, comb2.length());                        
                    }
                    if(j < comb1.length()){
                        comb1 = comb1.substring(j);
                    }else{
                        comb1 = comb1.substring(j+1, comb1.length());                        
                    }
                }
                if(j < comb1.length()){                    
                    if(comb1.charAt(j) != comb2.charAt(i)){
                         j = j + 1;
                    }
                }
            }
        }
        System.out.println(res);