g g g g g g g g g g g g g g
ar and calculate the dates elapsed between two dates
g g g g g g g g
import java.util.*; g
class dates g
{
gggg public static void main(String args[])
g g g g g
gggg {
gggggggg int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
g
gggggggg int d,m,y,d1,m1,y1,s,s1,i,x;
g
gggggggg Scanner br =new Scanner(System.in);
g g g
gggggggg s=0;
gggggggg s1=0;
gggggggg System.out.println("Enter First Date day : "); g g gg g g
gggggggg d=br.nextInt( ); g
gggggggg System.out.println("Enter month : "); g g g
gggggggg m=br.nextInt( ); g
gggggggg System.out.println("Enter year : "); g g g
gggggggg y=br.nextInt( ); g
gggggggg System.out.println("Enter Second Date day : "); g g g g g
gggggggg d1=br.nextInt( ); g
gggggggg System.out.println("Enter month : "); g g g
gggggggg m1=br.nextInt( ); g
gggggggg System.out.println("Enter year : "); g g g
gggggggg y1=br.nextInt( ); g
gggggggg for(i=1;i<m;i++)
gggggggg {
gggggggggggg s=s+a[i];
,gggggggg }
gggggggg if(y%4==0)
gggggggg s=s+1;
gggggggg s=s+d;
gggggggg for(i=0;i<m1;i++)
gggggggg {
gggggggggggg s1=s1+a[i];
gggggggg }
gggggggg if(y1%4==0)
gggggggg s1=s1+1;
gggggggg s1=s1+d1;
gggggggg x=s1-s;
gggggggg System.out.print("Total number of days between : " + d+"/"+m+"/"+y);
g g g g g g g g
gggggggg System.out.print(" and " + d1+"/"+m1+"/"+y1);
g g g g
gggggggg System.out.print(" is " + x); g g g g
gggg }
}
OUTPUT:
Enter First Date day :
g g gg g g
16
Enter month : g g g
10
Enter year : g g g
1952
Enter Second Date day :
g g g g g
24
,Enter month : g g g
12
Enter year : g g g
200
Total number of days between : 16/10/1952 and 24/12/2005 is 68
g g g g g g g g g g
Algorithm:
1. Start
g
2.Input first date ,month and year g g g g g
3.Input second date, month and year g g g g g
4. Start the loop
g g g
gggggggggg s=s+a[i];
gggggggg if(y%4==0) then s=s+1 and s=s+d; g g g g
ggggggggg next loop for(i=0;i<m1;i++)
g g
gggggggggggg s1=s1+a[i];
gggggggg if(y1%4==0) then s1=s1+1; g gg
gggggggg s1=s1+d1;
gggggggg x=s1-s;
5.Display total numbers between 2 dates. g g g g g
6.Stop
2.Input consists of the month number, the day of month and the year. Write a progr
g g g g g gg g g g g g g gg g g
am to calculate and print the corresponding day of the year
g g g g g g g g g g
import java.util.*; g
class January g
{
gggg public static void main(String args[ ])
g g g g g g
gggg {
, gggggggg int a[ ]={31,28,31,30,31,30,31,31,30,31,30,31};
g g
gggggggg int d,m,y,s,i;
g
gggggggg Scanner in=new Scanner (System.in);
g g g
gggggggg s=0;
gggggggg System.out.println("Enter day : "); g g g
gggggggg d=in.nextInt();
gggggggg System.out.println("Enter month : ");g g g
gggggggg m=in.nextInt();
gggggggg System.out.println("Enter year : "); g g g
gggggggg y=in.nextInt();
gggggggg for(i=0;i<m-1;i++)
gggggggg {
gggggggggggg s=s+a[i];
gggggggg }
gggggggg if(y%4==0)
gggggggg s=s+1;
gggggggg s=s+d;
gggggggg System.out.println("Total number of days : " + s);
g g g g g g g
gggg }
}
Output:
Enter day : g g g
5
Enter month : g g g
3
Enter year : g g g
2000