Java integer comparison method, value by value?

S?rgio

New member
I am doing a mastermind game in java using random integers. I am having difficulty with this method: comparing the secret code with the guess code and returning the number of matched numbers... how to do it? I have tried to use Integer.to.String and then comparing char by char with a while, yet it never works... for now it looks like this

int a = 0;
String c = Integer.toString(code);
String d = Integer.toString(guess);
while (a<=codedigits-1){
if ((char)c.charAt(a)== d.charAt(a)){
res++;
}
a++;}
return res;
 
Back
Top