Code:
import java.util.InputMismatchException;import java.util.Scanner;
public class LabAssignment_4
{
public static void main(String args[])
{
int day,month,year;
String dmy;
Scanner s=new Scanner(System.in);
while (true)
try
{
System.out.print("Enter the day : ");
day=s.nextInt();
System.out.print("Enter month : ");
month=s.nextInt();
System.out.print("Enter year : ");
year=s.nextInt();
dmy=date(day,month,year);
System.out.print(dmy);
break;
}
catch(InputMismatchException e1)
{
System.out.print("Please enter a valid integer value");
s.nextLine();
}
}
static String date(int a, int b, int c)
{
if((a>=1 && a<=31) && (b>=1 && b<=12) && (c>=1900 && c<=2099))
{
if((b==4 || b==6 || b==9 || b==11) && (a>=1 && a<=30))
return ("TRUE");
else if((b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12) && (a>=1 && a<=31))
return ("TRUE");
else if(b==2 && (a>=1 && a<=29)&& c%4==0)
return ("TRUE");
else if(b==2 && (a>=1 && a<=28)&& c%4!=0)
return ("TRUE");
else
return ("FALSE");
}
else
return ("FALSE");
}
}
No comments:
Post a Comment