import test2.TestUtility; import java.io.PrintStream; import java.util.ArrayList; public class Test2DShort { 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; /* This is the same problem as InversionCount except that you are looking for repeated numbers instead of numbers out of order. This solution is slightly inefficient in that you could terminate both loops as soon as isValid becomes false. */ // is this a valid sudoku row (i.e., no digits repeated)? boolean isValid = true; for (int i = 0; i < MAX; i++) { int elemi = ROW.get(i); for (int j = i + 1; j < MAX; j++) { int elemj = ROW.get(j); if (elemi == elemj) { isValid = false; } } } out.println(isValid); } }