2022年天干地支对照表,java实现

良田百顷,不在一亩;但有远志,不在当归

2022年天干地支对照表 干支日历表

生辰八字

干支纪年

为什么不会有甲丑年

农历月份

三九天

2022年三九天时间表

干支

什么是十二地支?地支由来详解

一文读懂阳历、阴历、公历、农历

//儒以文乱法,而侠以武犯禁
package test;
import java.util.Arrays;
public class Days {
    public static void main(String[] args) {
        String[] sky = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
        String[] ground = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
        int count = 0;
        int n = 0;
        String[] year = new String[60];
        for (int i = 0; i < sky.length; i++) {
            for (int j = 0; j < ground.length; j++) {
                if ((i & 1) == 1 && (j & 1) == 1||(i & 1) == 0 && (j & 1) == 0) {
                    year[j] = sky[i] + ground[j];
                    System.out.print(year[j] + " ");
                    count++;
                    n++;
                    if (n == 6) {
                        System.out.print("\n---------------------------------\n");
                        n = 0;
                    }
                }
            }
        }
        System.out.println("count = " + count);
    }
}

2022年天干地支对照表,java实现_第1张图片

用数组存贮总犯错,原因未知,用list就没问题

import java.util.ArrayList;

public class Days {
    public static void main(String[] args) {
        String[] sky = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
        String[] ground = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
        ArrayList<String> list = new ArrayList<>();
        int count = 0;
        int n = 0;
        String[] year = new String[60];
        String[] copy = new String[60];
        for (int i = 0; i < sky.length; i++) {
            for (int j = 0; j < ground.length; j++) {
                if ((i & 1) == 1 && (j & 1) == 1 || (i & 1) == 0 && (j & 1) == 0) {
                    year[j] = sky[i] + ground[j];
                    list.add(year[j]);
                    System.out.print(year[j] + " ");
                    count++;
                    n++;
                    if (n == 6) {
                        System.out.print("\n---------------------------------\n");
                        n = 0;
                    }
                }
                for (int k = 0; k < copy.length; k++) {
                    copy[k] = year[j];
                }
            }
        }
        int m = 0;
        System.out.print("count = " + count);
        System.out.print("\n---------------------------------------------------\n");
        for (String s : list) {
            System.out.print((s) + " ");
            m++;
            if (m == 12) {
                System.out.print("\n---------------------------------------------------\n");
                m = 0;
            }
        }
        int p = 0;
        System.out.print("count = " + count);
        System.out.print("\n---------------------------------------------------\n");
        for (int i = 0; i < year.length; i++) {
            System.out.print(year[i] + " ");
            p++;
            if (p == 12) {
                System.out.print("\n---------------------------------------------------\n");
                p = 0;
            }
        }
        int q = 0;
        System.out.print("count = " + count);
        System.out.print("\n---------------------------------------------------\n");
        for (int i = 0; i < copy.length; i++) {
            System.out.print(copy[i] + " ");
            q++;
            if (q == 12) {
                System.out.print("\n---------------------------------------------------\n");
                q = 0;
            }
        }
    }
}

2022年天干地支对照表,java实现_第2张图片
2022年天干地支对照表,java实现_第3张图片

你可能感兴趣的:(java)