1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import java.util.Scanner;
public class Main { public static String[] tiangan = {"jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren", "gui"}; public static String[] dizhi = {"zi", "chou", "yin", "mao", "chen", "si", "wu", "wei", "shen", "you", "xu", "hai"}; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int year = scan.nextInt(); int left = 0; int tianganIndex; int dizhiIndex; if(year >= 1900) { left = year - 1900; tianganIndex = (left % 10 + 6) % 10; dizhiIndex = left % 12;
} else { left = 1900 - year; tianganIndex = (6 - (left % 10) + 10) % 10; dizhiIndex = (0 + 12 - (left % 12)) % 12; } String tianganString = tiangan[tianganIndex]; String dizhiString = dizhi[dizhiIndex]; String nongliString = tianganString + dizhiString; System.out.println(nongliString); scan.close(); } }
|