-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsudokuCheck6cross6.java
More file actions
95 lines (84 loc) · 1.89 KB
/
sudokuCheck6cross6.java
File metadata and controls
95 lines (84 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.gokul.matrix;
public class TestSudoku6cross6 {
public static void main(String[] args) {
String[][] array1= {{"1","2","3","4","5","6"},
{"6","5","4","3","2","1"},
{"5","4","1","2","6","3"},
{"3","6","2","1","4","5"},
{"2","1","5","6","3","4"},
{"4","3","6","5","1","2"}};
checkSudoku(array1);
}
static boolean foundError=false;
public static void checkSudoku(String[][] strArray){
//Checking row wise 1 to 6 not repeated
String str=" ";
for(int row=0;row<strArray.length;row++){
for(int col=0;col<strArray.length;col++){
if(!str.contains(strArray[row][col]))
str=strArray[row][col]+str;
}
validateStr(str);
str=" ";
}
//Checking column wise 1 to 6 not repeated
for(int col=0;col<strArray.length;col++){
for(int row=0;row<strArray.length;row++){
if(!str.contains(strArray[row][col]))
str=str+strArray[row][col];
}
validateStr(str);
str=" ";
}
int count=0;
int a=0;
int b=2;
int c=0;
int d=3;
int flow=1;
while(count<3 && flow<3){
for(int row=a;row<b;row++){
for(int col=c;col<d;col++){
if(!str.contains(strArray[row][col]))
str=str+strArray[row][col];
}
}
validateStr(str);
count++;
if(count<3){
a+=2;
b+=2;}
else
{
flow++;
a=0;
b=2;
c=3;
d=6;
count=0;
}
str=" ";
}
if(foundError==false)
System.out.println("Your Sudoku looks Good...!!!");
}
public static void validateStr(String str){
if(foundError==false){
str=str.trim();
if(str.length()!=6){
System.out.println("Sudoku number repeated/Missed.Please check ");
foundError=true;
}
else if(str.length()==6 && foundError==false)
{
String content="123456";
for(char c:str.toCharArray()){
if(!content.contains(c+""))
{System.out.println("Non-sudoku letters found.Please check ");
foundError=true;
}
}
}
}
}
}