Help with very, very basic JAVA task

So, first, I want to make it clear, I'm not into programming, I've never been, but I'm taking a course about JAVA, and we got a task assigned about making a little game.
Basically, the program makes a 5 digits random number (every digit is different) and the user has to guess it, and, after every attempt the program prints out the amount of digits that are right in the correct spot, and the amount that its right but not in the correct spot. For the the first ones I make this and it works! (How to look for them after the user enters a number)(It's in Spanish because I'm from Uruguay :P) :

public static int cantBien (String ingreso, String numero) {
int contador = 0;
for (int i = 0; i < largo-1; i++) {
if (ingreso.charAt(i) == numero.charAt(i)) {
contador++;
}
}
return contador;

But I'm struggling to get the second ones work, I tried this but its returns is wrong data:

public static int cantReg (String ingreso, String numero) {
int contador = 0;
for (int j=0; j < largo-1; j++) {
for (int k=0; k < largo-1; k++) {
if(ingreso.charAt(k) == numero.charAt(k)) {
contador++;
}
}
}
return (contador-cantBien(ingreso,numero));

Hope you can help me!

Do you have any examples of what "wrong data" is ?

Did you work this out???

if the first loop is checking 0=0, 1=1, 2=2, 3=3 etc for correct position then shouldn't the other loop do:
0=0, 1=0, 2=0,3=0..
1=1, 2=1, 3=1..
2=2, 3=2..
... you just seem to be checking the characters against each other as per the first loop but doing it multiple times.

how about something like...

for (int j=0; j < largo-1; j++) {
    for (int k=j; k < largo-1; k++) {
        if(ingreso.charAt(k) == numero.charAt(j)) {
            contador++;
        }
    }
}

Off the top of my head... I'm thinking you need to search less each time as otherwise you'll be double counting where 2=1 and 1=2...

It's usually helpful to stick some debug output in there so you can see what the numbers are that a) it's looping on an b) what the values it's comparing are.

Also not sure where largo is coming from but assuming its the intended length of the number then the loop looks like it will finish too early???

k < largo -1 would only allow k from 0 - 4 if largo is 6 - therefore only 5 numbers checked

k <= largo would allow k from 0 - 5 if largo is 6 - therefore 6 numbers checked