天干地支 java

您所在的位置:网站首页 公元干支计算法 天干地支 java

天干地支 java

2023-10-23 02:28| 来源: 网络整理| 查看: 265

public class 干支纪年法 {

// 甲、乙、丙、丁、戊、己、庚、辛、壬、癸

//public static final int[] skyBranch = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

// 子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥

//public static final char[] earthBranch = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l' };

// 甲、乙、丙、丁、戊、己、庚、辛、壬、癸

public static final char[] skyBranch = new char[] { '甲','乙','丙','丁','戊','己','庚','辛','壬','癸'};

// 子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥

public static final char[] earthBranch = new char[] { '子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥' };

public static void main(String[] args) {

for (int i = 0; i < 2030; i++) {

try {

caculate(i);

if ((i % 20) == 0) {

System.out.println("");

} else {

System.out.println(",");

}

} catch (RuntimeException e) {

System.out.println("Year" + i + " met exception.");

}

}

}

private static void caculate(int i) {

if (i < 4) {

throw new IllegalArgumentException("The starting year must be greater than 4");

}

int realYear = i - 4;

System.out.print("year" + i + " =[" + skyBranch[realYear % 10] + "][" + earthBranch[realYear % 12] + "]");

}

}



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3