SHARE
TWEET

Untitled

a guest Nov 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Sudoku_Field {
  2.    
  3.     private static boolean isValidSudoku(int[] numbers) {
  4.        
  5.         if (numbers.length == 0 || numbers.length > 9) return false;
  6.         if (numbers == null) return false;
  7.        
  8.         int validSum = 0, rowSum = 0;
  9.         int[] summands = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
  10.        
  11.        
  12.         for (int i = 0; i <= 8; i++) {
  13.             validSum += summands[i];
  14.         }
  15.        
  16.         Out.println(validSum);
  17.        
  18.         for(int i = 0; i < 9; i++) {
  19.             int help = numbers[i];
  20.             for(int j = 1; j <= help; j++) {
  21.                 rowSum = rowSum+(10*10);
  22.             }
  23.         }
  24.         Out.println(rowSum);
  25.         if (validSum != rowSum) return false;
  26.         else return true;
  27.     }
  28.    
  29.     public static void main (String[] args) {
  30.        
  31.         int[] sudokuRow = new int[9];
  32.         int count = 1;
  33.        
  34.         do {
  35.             Out.print("Please input the " + count + ". number: ");
  36.             sudokuRow[(count-1)] = In.readInt();
  37.             count++;
  38.         } while (count <= 9);
  39.        
  40.         if(isValidSudoku(sudokuRow)) {
  41.             Out.print("Valid Sudoku row!");
  42.         } else {
  43.             Out.print("Invalid Sudoku row!");
  44.         }
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top