-2

I compare two number's digits.When digit's locations and values are correct,numofPositives is increased.When digit's location is false, value is true,numOfNegatives are increased.Here is my code that triggers the exception:

for ( i = 0; i < numDigits; i++){

    if (arrayOfSecretNumber[i] == arrayOfNumber[i]) {

        numOfPositive++;
        }else {
            for (int j = 0; j < numDigits; j++) {
                if (arrayOfNumber[i] == arrayOfSecretNumber[j]) {
                    numberOfNegative++;
                    break;
                }
            }
        }
    }
    return new Similarity(numOfPositive,numberOfNegative);
}
Banana
  • 2,255
  • 7
  • 31
  • 52
dkorkmaz
  • 3
  • 1

1 Answers1

0

java.lang.ArrayIndexOutOfBoundsException: occurs you try to access the Array element which is not even present in the Array.