1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import java.util.Scanner;
public class Isdate {
public static Scanner reader=new Scanner (System.in);
public static void main(String[] args)
{
int year,month,day;
boolean valid=true;
System.out.println("Enter year");
year=reader.nextInt();
System.out.println("Enter month");
month=reader.nextInt();
System.out.println("Enter day");
day=reader.nextInt();
if (month > 0 && month < 13 && day > 0 && day < 32) {
if ((day == 31) && ((month==4) || month==6 || month==9 || month==11)) {
System.out.println("31st of a month with 30 days");
valid=false;
}
if (day >= 30 && month == 2) {
System.out.println("February 30th or 31st");
valid=false;
}
if (month==2 && day==29 && year % 4 != 0) {
System.out.println("February 29th outside a leap year");
valid=false;
}
if (valid==true) { System.out.println("ok"); }
}
else { System.out.println("The month must be 1-12 and the day 1-31"); }
}
} |