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!