0

Help me to resolve this program? How to check date vaild or not? also tell me how to insert a month like jan,feb,etc

import java.util.Scanner; public class Date { public static void main(String[] args) { { int dd,mm,yyyy,no_of_days=0; Scanner sc=new Scanner(System.in); System.out.println("enter month"); mm=sc.nextInt(); System.out.println("enter date"); dd=sc.nextInt(); System.out.println("enter year"); yyyy=sc.nextInt(); System.out.println("Date is:"+dd+"_"+mm+"_"+yyyy); switch(mm) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: no_of_days=31; if(mm<=12) { System.out.println("vaild month"); } else { System.out.println("invaild month"); } if(yyyy%4==0) { no_of_days=29; System.out.println("leap year"); } else { System.out.println("not a leap year");} if(dd<=31) { System.out.println("vaiild date"); } else { System.out.println("invaild date");} break; case 4: case 6: case 9: case 11: no_of_days=30; if(mm<=12) { System.out.println("vaild month")

11th Dec 2018, 8:58 PM
Amol Sontakke
Amol Sontakke - avatar
1 Odpowiedź
+ 1
Checkimg date is valid or not, use an array. int[] days_in_month = {31, 29, 31, ...} if(dd > days_in_month[mm+1]) //valid days else // not valid days
11th Dec 2018, 9:24 PM
ShortCode