Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
/*
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
int i,j,k,a[10][10],o,x[100],y[100];
void display();
int getnum();
void solve(int [],int [],int);
int check(int ,int );
void main()
{
clrscr();
printf("\n\nEnter the elements of SUDOKU in rowwise.\n[ Enter '0' if element is absent. ]");
for(i=1;i<=9;i++)
for(j=1;j<=9;j++)
scanf("%d",'&', a[i][j]);
printf("\n\nEntered SUDOKU\n\n");
display();
printf("\nEnter any key for solution....\n");
getch();
o=getnum();
solve(x,y,1);
}
int getnum()
{
int c=0;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
if(a[i][j]==0)
{
c++;
x[c]=i;
y[c]=j;
}
}
}
return(c);
}
void display()
{
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
if(a[i][j]!=0)
printf(" %d",a[i][j]);
else
printf(" ");
}
printf("\n\n");
}
}
void solve(int p[100],int q[100],int n)
{
for(k=1;k<=9;k++)
for(i=p[n];i<=p[n];i++)
for(j=q[n];j<=q[n];j++)
{
a[i][j]=k;
if(n<0)
solve(p,q,n++);
int ch=check(1,0);
if(ch!=0)
{
display();
getch();
exit(0);
}
}
}
int check(int n,int r)
{
int f=0,cont=0;
if(r==1)
{
for(k=1;k<=9;k++)
{
for(i=n;i<=n;i++)
for(j=1;j<=9;j++)
{
if(k==a[i][j])
f++;
}
if(f!=1)
return(0);
else
cont++;
f=0;
}
if(cont!=9)
return(0);
else if(n==9)
check(1,0);
else
check(n++,1);
}
else
{
for(k=1;k<=9;k++)
{
for(i=1;i<=9;i++)
for(j=n;j<=n;j++)
{
if(k==a[i][j])
f++;
}
if(f!=1)
return(0);
else
cont++;
f=0;
}
if(cont!=9)
return(0);
else if(n!=9)
check(n++,1);
}}
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(426,266);
//}}
}
}
void display();
int getnum();
void solve(int [],int [],int);
int check(int a ,int );
int i,j,k,a[10][10],o,x[100],y[100];
private int i,j,k,o;
private int[] x = new int[100];
private int[] y = new int[100];
private int[][] a = new int[10][10];
getch()
printf("\nEnter any key for solution....\n");
scanf("%d",'&', a[i][j]);
[COLOR="Red"]void solve(int p[],int q[],int n) {[/COLOR]
for(k=1;k<=9;k++)
for(i=p[n];i<=p[n];i++)
for(j=q[n];j<=q[n];j++) {
a[i][j]=k;
if(n<0)
solve(p,q,n++);
int ch=check(1,0);
if(ch!=0) {
display();
getch();
exit(0);
}
}
}
[COLOR="Red"]void solve(int[] p,int[] q,int n) {[/COLOR]
for(k=1;k<=9;k++)
for(i=p[n];i<=p[n];i++)
for(j=q[n];j<=q[n];j++) {
a[i][j]=k;
if(n<0)
solve(p,q,n++);
int ch=check(1,0);
if(ch!=0) {
display();
getch();
exit(0);
}
}
}
/*
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet {
int i,j,k,o;
int[] x = new int[100];
int[] y = new int[100];
int[][] a = new int[10][10];
public void main() {
clrscr();
printf("\n\nEnter the elements of SUDOKU in rowwise.\n[ Enter '0' if element is absent. ]");
for(i=1;i<=9;i++)
for(j=1;j<=9;j++)
scanf("%d",'&', a[i][j]);
printf("\n\nEntered SUDOKU\n\n");
display();
printf("\nEnter any key for solution....\n");
getch();
o=getnum();
solve(x,y,1);
}
private int getnum() {
int c=0;
for(i=1;i<=9;i++) {
for(j=1;j<=9;j++) {
if(a[i][j]==0) {
c++;
x[c]=i;
y[c]=j;
}
}
}
return(c);
}
private void display() {
for(i=1;i<=9;i++) {
for(j=1;j<=9;j++) {
if(a[i][j]!=0)
printf(" %d",a[i][j]);
else
printf(" ");
}
printf("\n\n");
}
}
public void solve(int p[],int q[],int n) {
for(k=1;k<=9;k++)
for(i=p[n];i<=p[n];i++)
for(j=q[n];j<=q[n];j++) {
a[i][j]=k;
if(n<0)
solve(p,q,n++);
int ch=check(1,0);
if(ch!=0) {
display();
getch();
exit(0);
}
}
}
private int check(int n,int r) {
int f=0,cont=0;
if(r==1) {
for(k=1;k<=9;k++) {
for(i=n;i<=n;i++)
for(j=1;j<=9;j++) {
if(k==a[i][j])
f++;
}
if(f!=1)
return(0);
else
cont++;
f=0;
}
if(cont!=9)
return(0);
else if(n==9)
check(1,0);
else
check(n++,1);
} else {
for(k=1;k<=9;k++) {
for(i=1;i<=9;i++)
for(j=n;j<=n;j++) {
if(k==a[i][j])
f++;
}
if(f!=1)
return(0);
else
cont++;
f=0;
}
if(cont!=9)
return(0);
else if(n!=9)
check(n++,1);
}}
public void init() {
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(426,266);
//}}
}
}
private void getch(){
//hier dan de uitvoering van de methode
}
private void clscr(){
//hier dan de uitvoering van de methode
}
private void printf(String s){
//hier dan de uitvoering van de methode
}
private void scanf(String s, char c, int[][] a){
//hier dan de uitvoering van de methode
}
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.