Input a date from the keyboard in the format of yyyy-M-d
Calculate the number of days between the date and January 1, October 1, 1949.
For example:
User entered: 1949-10-2
Program output: 1
The user entered: 1949-11-1
Program output: 31
Import java. util .*;
Public class Test_8 {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Pipeline SC = new pipeline (System. in );
System. out. println ("Enter the date in the format of: YYYY-M-D :");
String str1 = SC. nextLine ();
String [] str2 = str1.split ("-");
Int year = Integer. parseInt (str2 [0]);
Int month = Integer. parseInt (str2 [1]);
Int day = Integer. parseInt (str2 [2]);
Calendar cal = new GregorianCalendar (year, month, day );
Date date1 = cal. getTime ();
Calendar cal2 = new GregorianCalendar (1949,10, 1 );
Date date2 = cal2.getTime ();
Long days = (date1.getTime ()-date2.getTime ()/(1000*60*60*24) + 1;
System. out. println ("the date you entered is the day of the year" + days +. ");
}
}