Thursday, September 18, 2008

DASTRAP ENTRY 1

//Jonathan F. Maralit , s22 , Terminal # 1
//This code determines the day when the user inputs a date
//in this order : mmddyyyy
//copyright goes to owner.


import java.util.*;
public class Zeller
{
public static void main (String[] args)
{
System.out.print("Input Date: ");
Scanner sc = new Scanner (System.in);
int date = sc.nextInt();
int m = date / 1000000;
int k = (date / 10000) % 100;
int D = date % 100;
int C = (date % 10000) / 100;
if (m == 1 || m == 2)
{m += 10;
D -= 1;}
else if (m > 3 && m <= 12)
m -= 2;
int f = k + ((13*m-1)/5) + D + (D/4) + (C/4) - 2*C;
int Day = f%7;
while (Day <0)
Day += 7;
if (Day == 0)
System.out.println("Sunday");
else if (Day == 1)
System.out.println("Monday");
else if (Day == 2)
System.out.println("Tuesday");
else if (Day == 3)
System.out.println("Wednesday");
else if (Day == 4)
System.out.println("Thursday");
else if (Day == 5)
System.out.println("Friday");
else if (Day == 6)
System.out.println("Saturday");

}
}

No comments: