import test2.TestUtility; import java.io.PrintStream; import java.util.ArrayList; public class Test2D { public static void main(String[] args) { PrintStream out = System.out; // get and print a random row of a sudoku puzzle final ArrayList ROW = TestUtility.sudokuRow(); out.println(ROW); // the number of elements in a row final int MAX = 9; /* If you started with InversionCount, then you need to add a variable that keeps track of the maximum number of repeats (maxRepeats). You also need a counter that counts the number of times that element i has been repeated. */ // is this a valid sudoku row (i.e., no digits repeated)? boolean isValid = true; // the maximum number of times any digit is repeated int maxRepeats = 1; for (int i = 0; i < MAX; i++) { int elemi = ROW.get(i); // the number of times elemi is repeated int repeats = 1; for (int j = i + 1; j < MAX; j++) { int elemj = ROW.get(j); if (elemi == elemj) { isValid = false; repeats++; } } if (repeats > maxRepeats) { maxRepeats = repeats; } } out.println(isValid); if (!isValid) { out.println("Maximum repeats: " + maxRepeats); } } }