Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not. If it is valid, ...

Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not.

If it is valid, display "VALID DATE", also compute and display the day number of the year for the date of birth. If it is invalid, display "INVALID DATE" and then terminate the program.

Testing of the program

Example 1

INPUT: Enter your date of birth in dd mm yyyy format
05
01
2010

OUTPUT: VALID DATE
5


Example 2

INPUT: Enter your date of birth in dd mm yyyy format
03
04
2010

OUTPUT: VALID DATE
93


Example 3

INPUT: Enter your date of birth in dd mm yyyy format
34
06
2010

OUTPUT: INVALID DATE
import java.util.*;
class ISCprac2011q03{
public static void main(String args[])
throws InputMismatchException{

Scanner scan=new Scanner(System.in);
System.out.println("Enter your date od birth in 
dd mm yyyy format : ");
int d=scan.nextInt();
int m=scan.nextInt();
int y=scan.nextInt();
int dom[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(y%400==0 || (y%100!=0 && y%4==0))
dom[1]=29;
if(d<=dom[m-1])
{
System.out.print("VALID DATE ");
int i,s=0;
for(i=0;i< m-1;i++)
s=s+dom[i];

s+=d;

System.out.print(s);
}else{
System.out.print("INVALID DATE");
}
}
}    

Have something to say? Log in to comment on this post.

0 comments