Sudoku in java
Write a program to check whether a given Sudoku solution is correct or not .
Write a program to check whether a given Sudoku solution is correct or not .
public class java9
{
public static void main(String[] args)
{
int Sudoku[][] = {{5, 3, 4, 6, 7, 8, 9, 1, 2},
{6, 7, 2, 1, 9, 5, 3, 4, 8},
{1, 9, 8, 3, 4, 2, 5, 6, 7},
{8, 5, 9, 7, 6, 1, 4, 2, 3},
{4, 2, 6, 8, 5, 3, 7, 9, 1},
{7, 1, 3, 9, 2, 4, 8, 5, 6},
{9, 6, 1, 5, 3, 7, 2, 8, 4},
{2, 8, 7, 4, 1, 9, 6, 3, 5},
{3, 4, 5, 2, 8, 6, 1, 7, 9}};
for(int i = 0; i< 9; i++)
{
int sum = 0;
for(int j =0; j < 9; j++)
{
sum = sum + Sudoku[i][j];
}
if(sum != 45)
{
System.out.println("wrong solution");
System.exit(0);
}
}
System.out.println("Correct solution");
}
}Output: Correct solution
Related Posts
Continue learning with these related articles

ICSE Class 9 Computer Applications Notes: Values, Data Types and Operators in Java
Easy-to-revise ICSE Class 9 Computer Applications notes on Java tokens, primitive data types, type conversion, and arithmetic, relational, logical, increment and ternary operators, with solved output questions and practice exercises.

ICSE Class 10 Computer Applications Sample Paper 2027 with Solutions
A full-length ICSE Class 10 Computer Applications sample paper for the 2027 board exam in the latest CISCE format: 20 MCQs, 10 short-answer questions and 6 Java programs, followed by complete solutions with explanations and solved BlueJ programs.
ICSE computer applications sample paper
ICSE computer applications sample paper (Set 3): ICSE Class 10 Computer Applications sample paper with important questions for computer exam practice.