Search for tiangan, dizhi, and Zodiac based on the year given by the user (Java source code)

Source: Internet
Author: User

In Chinese calendars, tiangan, dizhi, and Zodiac are arranged regularly. The sequence of tiangan is "A, B, and C, E, and Geng, Xin, Xi", and the sequence of Land support is "Zi, Yi, Mao, Chen, Wu, Wu, Wei, Chen, Wei ", the sequence of Chinese zodiac signs is "rat, ox, Tiger, Rabbit, dragon, Snake, horse, monkey, chicken, dog, and pig ". The Calculation Method of tiangan, dizhi, and Zodiac is very simple: the year minus 3 divided by 10 to get the remainder is a few, corresponding to the number of the day; the remainder of the year after dividing 3 by 12 is a number, which corresponds to the nth digit in the base. The calculation method of the Zodiac is the same as that of the base.

Public class shengxiao
{
Private Static final string MSG = "Run with an integer parameter, for example, Java shengxiao 2008 ";
Public void getinfo (INT year)
{
String STG [] = {"", "Jia", "B", "bing", "ding", "Wu", "Ji", "Geng ", "Xin", "Ren "};

String SDZ [] = {"Hai", "zi", "ugly", "Yin", "Mao", "Chen", "Si", "Wu ", "wei", "shen", "you", "shen "};
String ssx [] = {"pig", "rat", "Ox", "Tiger", "rabbit", "dragon", "snake", "horse ", "goat", "monkey", "chicken", "dog "};
Int I = (year-3) % 10;
Int J = (year-3) % 12;
System. Out. println ("input year: \ t" + year );
System. Out. println ("The days are \ t" + STG [I] + SDZ [J]);
System. Out. println ("corresponding to the Chinese zodiac: \ t" + ssx [J]);

}
Public static void main (string [] ARGs)
{
Shengxiao OBJ = new shengxiao ();
If (ARGs. Length <1)
{
System. Out. println (MSG );
Return;
}
Int iyear;
Try {iyear = integer. parseint (ARGs [0]);}
Catch (exception ERR)
{
System. Out. println (MSG );

Return;
}
OBJ. getinfo (iyear );
}
 
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.