13

用java实现一个3*3的矩阵使得矩阵横排竖排对角线的和等于13.规则是:只能用0-9,10个数字,每个数字只能用一次

解决方案 »

  1.   

    好无聊的题目啊....这种情况没有结果
    =================
    10个数每个数用一次....只用9个数,根据每行和为13得9数总和为39,故6不可能用到
    程序如下,无解
    =================
    public class matrix {
    int i[] = {0,1,2,3,4,5,7,8,9};
    int m[] = new int[9];
    boolean b[] = {false,false,false,false,false,false,false,false,false};
    int x=1;

    void getMatrix(){
    for(int a1=0;a1<9;a1++){
    m[0]=i[a1];
    System.out.println("计算进度:" + (a1*10+10) + "%");
    for(int a2=0;a2<9;a2++){
    m[1]=i[a2];
    for(int a3=0;a3<9;a3++){
    m[2]=i[a3];
    for(int a4=0;a4<9;a4++){
    m[3]=i[a4];
    for(int a5=0;a5<9;a5++){
    m[4]=i[a5];
    for(int a6=0;a6<9;a6++){
    m[5]=i[a6];
    for(int a7=0;a7<9;a7++){
    m[6]=i[a7];
    for(int a8=0;a8<9;a8++){
    m[7]=i[a8];
    for(int a9=0;a9<9;a9++){
    m[8]=i[a9];
    //
    for(int j=0;j<9;j++)
    b[j]=false;
    //
    if (b[a1])
         b[a1]=true;
    else
    break;
    if (b[a2])
         b[a2]=true;
    else
    break;
    if (b[a3])
         b[a3]=true;
    else
    break;
    if (b[a4])
         b[a4]=true;
    else
    break;
    if (b[a5])
         b[a5]=true;
    else
    break;
    if (b[a6])
         b[a6]=true;
    else
    break;
    if (b[a7])
         b[a7]=true;
    else
    break;
    if (b[a8])
         b[a8]=true;
    else
    break;
    if (b[a9])
         b[a9]=true;
    else
    break;

    if ((m[0]+m[1]+m[2]==13) && (m[3]+m[4]+m[5]==13) && (m[6]+m[7]+m[8]==13)
    && (m[0]+m[3]+m[6]==13) && (m[1]+m[4]+m[7]==13) && (m[2]+m[5]+m[8]==13)
    && (m[0]+m[4]+m[8]==13) && (m[2]+m[4]+m[6]==13)){
    System.out.println("第" + x + "种结果:");
    System.out.println(m[0] + " " + m[1] + " " + m[2]);
    System.out.println(m[3] + " " + m[4] + " " + m[5]);
    System.out.println(m[6] + " " + m[7] + " " + m[8]);
    System.out.println("==========================================");
    x++;
    }

    } } } } } } }

    }

    }

    }

    public static void main(String args[]){
    matrix m = new matrix();
    m.getMatrix();
    }

    }
      

  2.   

    imgonclick="<table><td><form method=post action=Deptform.jsp ><input type=hidden name=dcode value="+p.getDeptCode()+" /><input type=hidden name=daction value=add /><input type=image src=../../images/add.gif alt=增加 /></form></td><td><form method=post action=Deptform.jsp ><input type=hidden name=dcode value="+p.getDeptCode()+" /><input type=hidden name=daction value=update /><input type=image src=../../images/update.gif alt=修改 /></form></td><td><form method=post action=Deptform.jsp ><input type=hidden name=dcode value="+p.getDeptCode()+" /><input type=hidden name=daction value=delete /><input type=image src=../../images/delete.gif  alt=删除 /></form></td></table>";怎样在上面添加代码实现二次删除