Code:
import java.util.Scanner;
public class Date3
{
public static void main(String args[])
{
int day;
int month;
int year;
Scanner s=new Scanner(System.in);
System.out.print("Enter day\n");
day=s.nextInt();
System.out.print("Enter month\n");
month=s.nextInt();
System.out.print("Enter year\n");
year=s.nextInt();
if(day>=1 || day<=31 || month >=1 || month <= 12|| (year >=1900 && year <= 2099))
{
if((month ==4 || month ==6 || month ==9 ||month ==11) && (day>=1 && day<=30 )){
System.out.print("Date is valid");}
else if(month ==1 || month ==3 || month ==5 || month ==7 || month ==8 || month ==12)
{
System.out.print("Date is valid");}
else if(month==2&&(day>=1&&day<=29)){
System.out.print("Date is valid");}
else {
System.out.print("Date is invalid");
}
}
}
}
No comments:
Post a Comment