天干地支纪年法 Tiangan dizhi chronology
`天干地支,简称为干支,源自中国远古时代对天象的观测。十干是指阏逢、旃蒙、柔兆、强圉、著雍、屠维、上章、重光、玄黓、昭阳。十二支是指困敦、赤奋若、摄提格、单阏、执徐、大荒落、敦牂、协洽、涒滩、作噩、阉茂、大渊献。 [1]
简化后的天干地支:“甲、乙、丙、丁、戊、己、庚、辛、壬、癸”称为十天干,“子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥”称为十二地支。
十天干和十二地支依次相配,组成六十个基本单位,两者按固定的顺序相互配合,组成了干支纪元法。天干地支的发明影响深远,依旧在使用天干地支,用于历法、术数、计算、命名等各方面。 [1]
中文`
练习使用Java将公元纪年转化为天干地支纪年法
import java.util.Scanner;
public class Test {
public static void main(String[] args)
{
System.out.println("Enter Years,Sir.");
Scanner scanner=new Scanner(System.in);
int years = scanner.nextInt();
if (years >= 3) {
System.out.println("Successe");
int one = years - 3;
int sky = one % 10;
int land = one % 12;
switch (sky) {
case 1:
System.out.println("甲");
break;
case 2:
System.out.println("乙");
break;
case 3:
System.out.println("丙");
break;
case 4:
System.out.println("丁");
break;
case 5:
System.out.println("戊");
break;
case 6:
System.out.println("己");
break;
case 7:
System.out.println("庚");
break;
case 8:
System.out.println("辛");
break;
case 9:
System.out.println("壬");
break;
case 10:
System.out.println("癸");
break;
default:
System.out.println("Error2");
break;
}
switch (land) {
case 1:
System.out.println("子");
break;
case 2:
System.out.println("丑");
break;
case 3:
System.out.println("寅");
break;
case 4:
System.out.println("卯");
break;
case 5:
System.out.println("辰");
break;
case 6:
System.out.println("巳");
break;
case 7:
System.out.println("午");
break;
case 8:
System.out.println("未");
break;
case 9:
System.out.println("申");
break;
case 10:
System.out.println("酉");
break;
case 11:
System.out.println("戌");
break;
case 0:
System.out.println("亥");
break;
default:
System.out.println("Error3");
break;
}
}
else
{
System.out.println("Error0");
}
}
}
使用IDEA修改后的代码
import java.util.Scanner; public class Test { public static void main(String[] args) { System.out.println("Enter Years,Sir."); Scanner scanner=new Scanner(System.in); int years = scanner.nextInt(); if (years >= 3) { System.out.println("Enter Successes"); int one = years - 3; int sky = one % 10; int land = one % 12; switch (sky) { case 1 -> System.out.println("甲"); case 2 -> System.out.println("乙"); case 3 -> System.out.println("丙"); case 4 -> System.out.println("丁"); case 5 -> System.out.println("戊"); case 6 -> System.out.println("己"); case 7 -> System.out.println("庚"); case 8 -> System.out.println("辛"); case 9 -> System.out.println("壬"); case 0 -> System.out.println("癸"); default -> System.out.println("Error2"); } switch (land) { case 1 -> System.out.println("子"); case 2 -> System.out.println("丑"); case 3 -> System.out.println("寅"); case 4 -> System.out.println("卯"); case 5 -> System.out.println("辰"); case 6 -> System.out.println("巳"); case 7 -> System.out.println("午"); case 8 -> System.out.println("未"); case 9 -> System.out.println("申"); case 10 -> System.out.println("酉"); case 11 -> System.out.println("戌"); case 0 -> System.out.println("亥"); default -> System.out.println("Error3"); } } else { System.out.println("Error0"); } }
}