/**
*@author:518ad-ccn
*date:Dec 16, 2011
*describe:计算天干地支,12生肖
*计算规则相对简单,详细计算规则请参照百度百科http://baike.baidu.com/view/13672.htm
*/
public class TianGanDizhiShengXiao{
private final static String[][] tgdz = new String[][]{
{"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"}//10天干
,{"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"}};//12地支
//12生肖,(注:12生肖对应12地支,即子鼠,丑牛,寅虎依此类推)
private final static String[] animalYear =
new String[]{"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
private final static int startYear = 1804;//定义起始年,1804年为甲子年属鼠
/**获取当前年份与起始年之间的差值**/
public static int subtractYear(int year){
int jiaziYear = startYear;
if(year
jiaziYear = jiaziYear-(60+60*((jiaziYear-year)/60));//60年一个周期
}
return year-jiaziYear;
}
/**获取该年的天干名称**/
public static String getTianGanName(int year){
String name = tgdz[0][subtractYear(year)%10];
return name;
}
/**获取该年的地支名称**/
public static String getDiZhiName(int year){
String name = tgdz[1][subtractYear(year)%12];
return name;
}
/**
* 获取该年的天干、地支名称
* @param year 年份
* @return
*/
public static String getTGDZName(int year){
String name = getTianGanName(year)+ getDiZhiName(year);
return name;
}
/**
* 获取该年的生肖名称
* @param year 年份
* @return
*/
public static String getAnimalYearName(int year){
String name = animalYear[subtractYear(year)%12];
return name;
}
/**
* @param args
*/
public static void main(String[] args) {
int i = 0;
for(int k = startYear;k<2050;k++){
System.out.print(k+":"+getTGDZName(k)+ "年属"+getAnimalYearName(k));
if(++i%tgdz[0].length == 0){
System.out.print("\n");
}
}
//System.out.print(getTGDZName(2011));
}
}
///###########输出################//
1804:甲子年属鼠1805:乙丑年属牛1806:丙寅年属虎1807:丁卯年属兔1808:戊辰年属龙1809:己巳年属蛇1810:庚午年属马1811:辛未年属羊1812:壬申年属猴1813:癸酉年属鸡
1814:甲戌年属狗1815:乙亥年属猪1816:丙子年属鼠1817:丁丑年属牛1818:戊寅年属虎1819:己卯年属兔1820:庚辰年属龙1821:辛巳年属蛇1822:壬午年属马1823:癸未年属羊
1824:甲申年属猴1825:乙酉年属鸡1826:丙戌年属狗1827:丁亥年属猪1828:戊子年属鼠1829:己丑年属牛1830:庚寅年属虎1831:辛卯年属兔1832:壬辰年属龙1833:癸巳年属蛇
1834:甲午年属马1835:乙未年属羊1836:丙申年属猴1837:丁酉年属鸡1838:戊戌年属狗1839:己亥年属猪1840:庚子年属鼠1841:辛丑年属牛1842:壬寅年属虎1843:癸卯年属兔
1844:甲辰年属龙1845:乙巳年属蛇1846:丙午年属马1847:丁未年属羊1848:戊申年属猴1849:己酉年属鸡1850:庚戌年属狗1851:辛亥年属猪1852:壬子年属鼠1853:癸丑年属牛
1854:甲寅年属虎1855:乙卯年属兔1856:丙辰年属龙1857:丁巳年属蛇1858:戊午年属马1859:己未年属羊1860:庚申年属猴1861:辛酉年属鸡1862:壬戌年属狗1863:癸亥年属猪
1864:甲子年属鼠1865:乙丑年属牛1866:丙寅年属虎1867:丁卯年属兔1868:戊辰年属龙1869:己巳年属蛇1870:庚午年属马1871:辛未年属羊1872:壬申年属猴1873:癸酉年属鸡
1874:甲戌年属狗1875:乙亥年属猪1876:丙子年属鼠1877:丁丑年属牛1878:戊寅年属虎1879:己卯年属兔1880:庚辰年属龙1881:辛巳年属蛇1882:壬午年属马1883:癸未年属羊
1884:甲申年属猴1885:乙酉年属鸡1886:丙戌年属狗1887:丁亥年属猪1888:戊子年属鼠1889:己丑年属牛1890:庚寅年属虎1891:辛卯年属兔1892:壬辰年属龙1893:癸巳年属蛇
1894:甲午年属马1895:乙未年属羊1896:丙申年属猴1897:丁酉年属鸡1898:戊戌年属狗1899:己亥年属猪1900:庚子年属鼠1901:辛丑年属牛1902:壬寅年属虎1903:癸卯年属兔
1904:甲辰年属龙1905:乙巳年属蛇1906:丙午年属马1907:丁未年属羊1908:戊申年属猴1909:己酉年属鸡1910:庚戌年属狗1911:辛亥年属猪1912:壬子年属鼠1913:癸丑年属牛
1914:甲寅年属虎1915:乙卯年属兔1916:丙辰年属龙1917:丁巳年属蛇1918:戊午年属马1919:己未年属羊1920:庚申年属猴1921:辛酉年属鸡1922:壬戌年属狗1923:癸亥年属猪
1924:甲子年属鼠1925:乙丑年属牛1926:丙寅年属虎1927:丁卯年属兔1928:戊辰年属龙1929:己巳年属蛇1930:庚午年属马1931:辛未年属羊1932:壬申年属猴1933:癸酉年属鸡
1934:甲戌年属狗1935:乙亥年属猪1936:丙子年属鼠1937:丁丑年属牛1938:戊寅年属虎1939:己卯年属兔1940:庚辰年属龙1941:辛巳年属蛇1942:壬午年属马1943:癸未年属羊
1944:甲申年属猴1945:乙酉年属鸡1946:丙戌年属狗1947:丁亥年属猪1948:戊子年属鼠1949:己丑年属牛1950:庚寅年属虎1951:辛卯年属兔1952:壬辰年属龙1953:癸巳年属蛇
1954:甲午年属马1955:乙未年属羊1956:丙申年属猴1957:丁酉年属鸡1958:戊戌年属狗1959:己亥年属猪1960:庚子年属鼠1961:辛丑年属牛1962:壬寅年属虎1963:癸卯年属兔
1964:甲辰年属龙1965:乙巳年属蛇1966:丙午年属马1967:丁未年属羊1968:戊申年属猴1969:己酉年属鸡1970:庚戌年属狗1971:辛亥年属猪1972:壬子年属鼠1973:癸丑年属牛
1974:甲寅年属虎1975:乙卯年属兔1976:丙辰年属龙1977:丁巳年属蛇1978:戊午年属马1979:己未年属羊1980:庚申年属猴1981:辛酉年属鸡1982:壬戌年属狗1983:癸亥年属猪
1984:甲子年属鼠1985:乙丑年属牛1986:丙寅年属虎1987:丁卯年属兔1988:戊辰年属龙1989:己巳年属蛇1990:庚午年属马1991:辛未年属羊1992:壬申年属猴1993:癸酉年属鸡
1994:甲戌年属狗1995:乙亥年属猪1996:丙子年属鼠1997:丁丑年属牛1998:戊寅年属虎1999:己卯年属兔2000:庚辰年属龙2001:辛巳年属蛇2002:壬午年属马2003:癸未年属羊
2004:甲申年属猴2005:乙酉年属鸡2006:丙戌年属狗2007:丁亥年属猪2008:戊子年属鼠2009:己丑年属牛2010:庚寅年属虎2011:辛卯年属兔2012:壬辰年属龙2013:癸巳年属蛇
2014:甲午年属马2015:乙未年属羊2016:丙申年属猴2017:丁酉年属鸡2018:戊戌年属狗2019:己亥年属猪2020:庚子年属鼠2021:辛丑年属牛2022:壬寅年属虎2023:癸卯年属兔
2024:甲辰年属龙2025:乙巳年属蛇2026:丙午年属马2027:丁未年属羊2028:戊申年属猴2029:己酉年属鸡2030:庚戌年属狗2031:辛亥年属猪2032:壬子年属鼠2033:癸丑年属牛
2034:甲寅年属虎2035:乙卯年属兔2036:丙辰年属龙2037:丁巳年属蛇2038:戊午年属马2039:己未年属羊2040:庚申年属猴2041:辛酉年属鸡2042:壬戌年属狗2043:癸亥年属猪
2044:甲子年属鼠2045:乙丑年属牛2046:丙寅年属虎2047:丁卯年属兔2048:戊辰年属龙2049:己巳年属蛇