China Naming Network - Eight-character lottery - Who has the algorithm about the twenty-four solar terms, and finally the code realized in java?
Who has the algorithm about the twenty-four solar terms, and finally the code realized in java?
Import java.util. *; /* * The rule/appendix /f2.htm here exceeds the number of words. Let me indent and delete */public solar terms {public static void main (string [] s) throwsexception {solar terms st = new solar terms (); if(s . length = = 3){ system . out . println(ST . getsoralterm(integer . parse int(s[0])),Integer.parseInt(s[ 1]),integer . parse int(s[2])); } system . out . println(ST . getsoralterm(2009, 1,5)); system . out . println(ST . getsoralterm(2009, 1,20)); system . out . println(ST . getsoralterm(2009, 1,23)); system . out . println(ST . getsoralterm(2009,2, 18)); } final static long [] terminfo = new long [] {0,21208,42467,63836,85337, 1070 14, 128867,/kloc. 173 149, 195558 private static final string [] solar $ TERM = new string [] {"slight cold", "severe cold", "beginning of spring", "rain", "shock", "vernal equinox", "Qingming", "Grain Rain", "long summer" and "xiaoman" "Summer Solstice" public SolarTerm(){}/** The core method of obtaining solar terms according to the date */public string getsoralterm (date) {calendar cal = calendar.getinstance (); Cal.setTime (date); Int y = cal.get (calendar. Year); Int m = cal.get (calendar. Month)+1; Int d = cal.get (calendar. Month day); Returns getSoralTerm(y, m, d); }/* * The core method is based on the date (Y year, M month, D day) */public string getsoralterm (int y, int m, int d) {string solar terms; if (d == sTerm(y,(m- 1)* 2))solarTerms = SolarTerm[(m- 1)* 2]; else if (d == sTerm(y,(m- 1)* 2+ 1))solarTerms = SolarTerm[(m- 1)* 2+ 1]; Else{// Here, non-solar terms = ""; } returns solar terms}/= = = What day is the nth solar term in year Y (starting from 0 slight cold)? private int stern (int y, int n) {Calendar cal = calendar.getinstance (); cal.set( 1900,0,6,2,5,0); long temp = cal.getTime()。 getTime(); Cal.setTime (new date ((long)) ((31556925974.7 * (y-1900)+terminfo [n] * 60000l)+temp)); Return to cal.get (calendar. Month day); }}