当前位置: 代码迷 >> Java相关 >> JAVA程序
  详细解决方案

JAVA程序

热度:173   发布时间:2005-12-29 10:21:00.0
十分感谢能抽出时间帮我想题
一会儿我就要交程序了,也许会被退回来,但是很高兴能得到帮助
----------------解决方案--------------------------------------------------------
元旦快到了 大家新年快乐
以后有问题还请多多帮助
----------------解决方案--------------------------------------------------------
能 告诉我 xy ji dt 都 代表什么吗
我 知道你java 一定是很强的 可没有注视我 看 不懂

----------------解决方案--------------------------------------------------------

// 用swing写的 用到了递归算法
import javax.swing.*;
public class Queens
{
int[] a=new int[8];
int[] b=new int[15];
int[] c=new int[15];
int[][] Queen=new int[8][8];

void next(int i)
{
for(int j=0;j<8;j++)
{
if(a[j]==0&&b[i+j]==0&&c[i-j+7]==0)
{
a[j]=b[i+j]=c[i-j+7]=1;
Queen[i][j]=1;
if(i<7)
next(i+1);//递归
else
{
String output = new String();
for ( int m= 0; m< 8; m++ )
{
for ( int n= 0; n< 8; n++ )
output += " "+Queen[m][n]+" " ;
output +="\n";
} //对每种可能的情况以0、1表示(1表示皇后)输出
JTextArea outputArea = new JTextArea();
outputArea.setText( output );
JOptionPane.showMessageDialog( null, outputArea,"One possible distribution ",JOptionPane.INFORMATION_MESSAGE );
}
a[j]=b[i+j]=c[i-j+7]=Queen[i][j]=0;
}
}
}

public static void main(String args[])
{
Queens one=new Queens();
one.next(0);
System.exit(0);
}
}


----------------解决方案--------------------------------------------------------
  相关解决方案