Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sudoku_Field {
- private static boolean isValidSudoku(int[] numbers) {
- if (numbers.length == 0 || numbers.length > 9) return false;
- if (numbers == null) return false;
- int validSum = 0, rowSum = 0;
- int[] summands = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
- for (int i = 0; i <= 8; i++) {
- validSum += summands[i];
- }
- Out.println(validSum);
- for(int i = 0; i < 9; i++) {
- int help = numbers[i];
- for(int j = 1; j <= help; j++) {
- rowSum = rowSum+(10*10);
- }
- }
- Out.println(rowSum);
- if (validSum != rowSum) return false;
- else return true;
- }
- public static void main (String[] args) {
- int[] sudokuRow = new int[9];
- int count = 1;
- do {
- Out.print("Please input the " + count + ". number: ");
- sudokuRow[(count-1)] = In.readInt();
- count++;
- } while (count <= 9);
- if(isValidSudoku(sudokuRow)) {
- Out.print("Valid Sudoku row!");
- } else {
- Out.print("Invalid Sudoku row!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement