i got the program to work but the problem is that when i take my 2nd guess the program doesn't recognize the correct numbers being used and the correct positions of the numbers also i wanted to add a counter of how many tries it took for the user to guess the correct answer is there some way add it. can you help me find the problem here are my codes
import java.util.*;
public class m {
public static void main(String[] args) {
Random rand = new Random();
Scanner console = new Scanner(System.in);
System.out.println("Choose the length of the number you will be trying to guess: ");
int n = console.nextInt();
System.out.println("Enter your guess: ");
int entry = console.nextInt();
int[] guess = new int[n];
for (int i = n - 1; i >= 0; i--) {
guess[i] = entry % 10;
entry = entry / 10;
}
System.out.println("Guess Array Contains " + java.util.Arrays.toString(guess));
int[] nCode = new int[n];
for (int j = 0; j < n; j++) {
nCode[j] = rand.nextInt(10);
}
System.out.println("nCode Array Contains " + java.util.Arrays.toString(nCode));
do {
Check(nCode, guess, n);
System.out.println("Enter your next guess: ");
guess = new int[console.nextInt()];
} while (!nCode.equals(guess));
System.out.println("You Win!");
}
private static void Check(int[] a, int[] b, int length) {
int rightSpot = 0;
int wrongSpot = 0;
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
int checka = a[i];
int checkb = b[j];
if (checka == checkb && i == j) {
rightSpot++;
} else if (checka == checkb && i != j) {
wrongSpot++;
}
else if (a.equals(b)) {
System.out.println("That answer is correct!");
rightSpot = length;
wrongSpot = 0;
}
}
}
System.out.println(rightSpot + " of your digits are correct and in the "
+ "correct spot.");
System.out.println(wrongSpot + " of your digits are correct but in the "
+ "incorrect spot.");
}
}