class ZellersCongruence { /** * Calculate day of week using Zeller's Congruence * * For the Gregorian calendar * h =(q + floor(13(m + 1) / 5) + K + floor(K / 4) + floor(J/ 4) + 5J) % 7 * * For Julian calendar * h =(q + floor(13(m + 1) / 5) + K + floor(K / 4) + 5 + 6J) % 7 * * where * h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ...) * q is the day of the month * m is the month (3 = March, 4 = April, 5 = May, ..., 14 = February) * K the year of the century (year % 100). * J is the century (actually floor(year/100)) (For example, in 1995 the century would be 19, even though it was the 20th century.) * * NOTE: In this algorithm January and February are ...
class VarArgs { public static void main(String[] args) { System.out.println(sum(1)); System.out.println(sum(1, 2)); System.out.println(sum(1, 2, 3)); System.out.println(sum(1, 2, 3, 4)); } static int sum(int...args) { int sum = 0; for (int i = 0; i < args.length; i++) sum += args[i]; return sum; } }
Comments
Post a Comment
Post Your Valuable Comments