Write a java program to read a string containing the date in DD-MM-YYYY format. find the number of days in the given month.
Note – In leap year February has got 29 days.
The return type is the integer having a number of days.
Input and Output Format:
Input consists of a string.
The output consists of an integer.
Refer sample output for formatting specifications.
Sample Input 1:
12-06-2012
Sample Output 1:
30
Sample Input 2:
10-02-2012
Sample Output 2:
29
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class User { public static void main(String[] args) throws IOException, ParseException { // TODO Auto-generated method stub String s1="10-02-2012"; SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy"); Calendar cal=Calendar.getInstance(); Date d1=sdf.parse(s1); cal.setTime(d1); int n=cal.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println(n); } }