For this programming assignment, we are supposed to find the index of a duplicate in this array for one row of a sudoku puzzle. I have this method, static boolean equals(int[] a, int[] a2):
boolean isValue = true;
int[] dataRow = { 9, 8, 7, 6, 5, 4, 3, 2, 8 };
int[] chk = { 9, 8, 7, 6, 5, 4, 3, 1, 8 };
isValue = Arrays.equals(dataRow, chk);
int i, j;
for (i = 0; i < dataRow.length; i++)
{
for (j = 0; j < dataRow.length; j++)
{
if (dataRow[i] == dataRow[j])
{
System.out.println("Duplicate - " + dataRow[i] + " found at index " + i + " and " + j);
//--8 found at index 8 and 1
This program right here simply prints out this: Duplicate - 9 found at index 0 and 0 which means that no duplicate is found. I commented that 8 is found at index 8 and 1. I'm just not sure how to print out where the duplicate was found. I tried modifying the if statement, but that didn't work: if (dataRow[i] != chk[j]), if (dataRow[i] == chk[i]). I also tried putting the nested for loop into a while loop: while (!isValue), but that didn't work either. I think my professor also wants to make sure all the values in the array are between 1-9, and my idea is something like this: while (!isValue && (dataRow >= 1 && dataRow <= 9)), but I'm not sure if that will work. I appreciate any help you guys can give me.