laD a program that determines the d Writeoplex algorithm tha
Solution
This Program computes exatcly the Julian day of entered Date,Month,Year
import java.util.*;
public class CalculateJDN
{
public static void main(String[] args)
{
long JDN;
double years,days;
int intRes1=0,startYear=4713,month,date;//Taking start year as 4713
System.out.println(\"Enter the date :\"); // taking input for date
Scanner sc = new Scanner(System.in);
date = sc.nextInt();
System.out.println(\"Enter the month:\");
month=sc.nextInt(); // taking input for month
System.out.println(\"Enter the year: \"):
year=sc.nextInt(); // taking input for year
JDN = getNumdays(year); // storing result in JDN variable
System.out.println(\"The Day of this julian date is : \");
int intRes1 = (JDN+1)%7; // finally calculating the day
if(intRes1 == 0)
System.out.println(\"Sunday\");
else if(intRes1 == 1)
System.out.println(\"Monday\");
else if(intRes1 == 2)
System.out.println(\"Tuesday\");
else if(intRes1 == 3)
System.out.println(\"Wednesday\");
else if(intRes1 == 4)
System.out.println(\"Thursday\");
else if(intRes1 == 5)
System.out.println(\"Friday\");
else
System.out.println(\"Saturday\"):
}
int getnumdaysofMonth(int month) // This method returns days of months
{
int numdays=0;
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month ==10 || month == 12) // Calculating no of //days for the month if it has 30 or 31.
numdays=31;
else if(month == 2)
numdays == 28+getleapyear(year);
else
numdays = 30;
return numdays;
}
int getcurrentdays(int month)
{
int numdays=0;
for(int i=1;i<month;i++)
{
numdays = numdays+getnumdaysofMonth(i); //Getting number of days of current till current date in the year
}
numdays=numdays+date;
}
int getleapyear(int year) // validating whether the entered year is leap year or not.
{
if(year % 400 == 0 ) // If year is divisible by 400 then it is a leap year
return 1;
else if(year%4 == 0 && year % 100 ==0) // If the year is divisible by both 4 and 100 then it is a leap year
return 1;
else return 0;
}
long getNumDays(int year) // calculating total number of days till date.
{
long numdays=0;
for(int i=startYear;i>=0;i--)
{
numdays = numdays +365;
}
for(int i=1;i<=year;i++)
{
numdays=numdays+365;
if(i>1582) // The year from georgian calendar will have the leap year count
{
numdays=numdays+365+getleapyear(i);
}
else if(i == year)
numdays = numdays + getcurrentdays(month);
return numdays;
}
}


