编程之美_002中国象棋将帅问题

来源:互联网 发布:proe是什么软件 编辑:程序博客网 时间:2024/04/30 22:15
//中国象棋将帅问题//A,表示将,B表示帅//A,B运行的位置坐标//1 2 3//4 5 6//7 8 9//A,B的位置不能再同一列//打印所有满足条件的解public class Test{    public static void main(String[] args)    {        for (int i = 1; i <= 9; i++)        {            for (int j = 1; j <= 9; j++)            {                if (i % 3 != j % 3)                {                    System.out.println("A:" + i + " B:" + j);                }            }        }    }}

输出结果:

A:1 B:2A:1 B:3A:1 B:5A:1 B:6A:1 B:8A:1 B:9A:2 B:1A:2 B:3A:2 B:4A:2 B:6A:2 B:7A:2 B:9A:3 B:1A:3 B:2A:3 B:4A:3 B:5A:3 B:7A:3 B:8A:4 B:2A:4 B:3A:4 B:5A:4 B:6A:4 B:8A:4 B:9A:5 B:1A:5 B:3A:5 B:4A:5 B:6A:5 B:7A:5 B:9A:6 B:1A:6 B:2A:6 B:4A:6 B:5A:6 B:7A:6 B:8A:7 B:2A:7 B:3A:7 B:5A:7 B:6A:7 B:8A:7 B:9A:8 B:1A:8 B:3A:8 B:4A:8 B:6A:8 B:7A:8 B:9A:9 B:1A:9 B:2A:9 B:4A:9 B:5A:9 B:7A:9 B:8


原创粉丝点击