Java Print Sudoku Box Algorithm

Byul·2023년 6월 14일

Java

목록 보기
8/10
for (int row = 0; row < 9; row += 3) {
    for (int col = 0; col < 9; col += 3) {
        for (int i = row; i < row + 3; i++) {
            for (int j = col; j < col + 3; j++) {
                System.out.print(i + "" + j + " ");
            }
            System.out.print("  ");
        }
        System.out.println();
    }
    if (row == 0 || row == 3) System.out.println();
}

result:

00 01 02   10 11 12   20 21 22   
03 04 05   13 14 15   23 24 25   
06 07 08   16 17 18   26 27 28   

30 31 32   40 41 42   50 51 52   
33 34 35   43 44 45   53 54 55   
36 37 38   46 47 48   56 57 58   

60 61 62   70 71 72   80 81 82   
63 64 65   73 74 75   83 84 85   
66 67 68   76 77 78   86 87 88
profile
junior backend developer

0개의 댓글