1 Packagetest8_19;2 3 ImportJava.util.Scanner;4 5 Public classCheckdate {6 Public Static voidMain (String args[]) {7Checkdate CD =Newcheckdate ();8Scanner reader =NewScanner (system.in);9 while(true) {TenSystem.out.println ("Enter a Date:"); OneString date =reader.nextline (); A if(CD. Checkdateformat (date)) { -System.out.println ("Yes"); -}Else { theSystem.out.println ("No"); - - } - } + } - + Public BooleanCheckdateformat (String date) { AString regex = "[1-2]\\d{3}. [0-1] [0-9]. [0-3] [0-9] "; at - if(Date.matches (regex)) { - //get Year month day of String -String year = date.substring (0, 4); - String Month; -String day = date.substring (8,10); in - if(Date.substring (5, 6). Equals ("0")) { tomonth = date.substring (6, 7);//0-9 Month +}Else { -month = date.substring (5, 7);//10-12 Month the } * $ if(Date.substring (8, 9). Equals ("0")) {Panax NotoginsengDay = date.substring (9, 10);//0-9 Day -}Else { theDay = date.substring (8, 10);//10-31 Day + } A //get Year month day of int the inty =Integer.parseint (year); + intm =Integer.parseint (month); - intD =Integer.parseint (day); $System.out.println ("y=" +y+ "m=" +m+ "d=" +d); $ - //if ((M >= 1 && m <=) && (d >= 1 && d <=)) { - Switch(m) { the Case2:if(Isleapyear (y)) { - if(d <= 29) {Wuyi return true; the}Else { - return false; Wu } - } About Else{if(d <= 28) { $ return true; -}Else { - return false; - } A } + the Case1: - Case3: $ Case5: the Case7: the Case8: the Case10: the Case12:if(d <= 31) { - return true; in}Else { the return false; the } About Case4: the Case6: the Case9: the Case11:if(d <= 30) { + return true; -}Else { the return false;Bayi } the default:return false; the - } - } the Else{ the return false; the } the } - the the the Public BooleanIsleapyear (intYear ) {94 if(year% 4 = = 0 && year%! = 0 | | year% 400 = = 0) { the return true; the}Else { the return false;98 } About } - 101}