Write a java program to find number of days in the given month using date

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:
Sample Output 1:

Sample Input 2:
Sample Output 2:

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);
int n=cal.getActualMaximum(Calendar.DAY_OF_MONTH);


Add a Comment

Your email address will not be published. Required fields are marked *

sixteen − three =