NUMBER OF DAYS in Java

Given the number of the month, your task is to calculate the number of days present in the particular month.

Note:- Consider non-leap year

User task: Since this is a functional problem you do not have to worry about the input. You just have to complete the function numberofdays() which contains M as a parameter.

Constraints:- 1 <= M <= 12

Output Print the number of days in the particular month.

Example Input

``1``

Output

``31``

Solution of Number of Days :–

``````import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
static void numberofdays(int days)
{
System.out.println(days);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int month = sc.nextInt();

if(month==1)
{
numberofdays(31);
}
else if(month==2)
{
numberofdays(28);
}
else if(month==3)
{
numberofdays(31);
}
else if(month==4)
{
numberofdays(30);
}
else if(month==5)
{
numberofdays(31);
}
else if(month==6)
{
numberofdays(30);
}
else if(month==7)
{
numberofdays(31);
}
else if(month==8)
{
numberofdays(31);
}
else if(month==9)
{
numberofdays(30);
}
else if(month==10)
{
numberofdays(31);
}
else if(month==11)
{
numberofdays(30);
}
else{
numberofdays(31);
}
}
}``````