Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java get number of days in month

// for example, february of 2000 
YearMonth.of(2000, 2).lengthOfMonth();
Comment

find the no of days in a month based on year in java

import java.util.*;
 
import java.time.YearMonth;
 
public class GetNumberOfDaysInMonthJava {
 
    public static void main(String[] args) {
        // Get number of days in given month of the year
      	int year,month;
      	Scanner input = new Scanner(System.in);
      	year = input.nextInt();
      	month = input.nextInt();
        int numberOfDaysInMonth1 = getNumberOfDaysInMonth(year, month);
        System.out.println("Number of days in Feb 2019: "+numberOfDaysInMonth1);
 
        int numberOfDaysInMonth2 = getNumberOfDaysInMonth(2020, 2);
        System.out.println("Number of days in Feb 2020: "+numberOfDaysInMonth2);
 
    }
 
    // Method to get number of days in month
    public static int getNumberOfDaysInMonth(int year,int month)
    {
        YearMonth yearMonthObject = YearMonth.of(year, month);
        int daysInMonth = yearMonthObject.lengthOfMonth();
        return daysInMonth;
    }
}
 
Comment

PREVIOUS NEXT
Code Example
Java :: Get the SUM of integers in List JAVA 
Java :: java 8 group a collections by 2 property 
Java :: java random 5 digit int 
Java :: double min value java 
Java :: text.settextcolor android 
Java :: java print output 
Java :: java thread lambda 
Java :: install java 8 on windows 10 
Java :: arrays.fill java 
Java :: java hello world 
Java :: worldedit set random blocks 
Java :: java boolean 2d array 
Java :: joptionpane 
Java :: Java program to find the sum of first 100 numbers 
Java :: get hashmap into array 
Java :: recyclerview stop scrolling 
Java :: java jpa criteriabuilder in xample 
Java :: java localtime format 
Java :: how to increment character in java 
Java :: read integer input java 
Java :: loop through string in java 
Java :: hashmap foreach 
Java :: android alertdialog setSingleChoiceItems 
Java :: priority queue java comparator lambda 
Java :: check instance of java 
Java :: kotlin variable in string 
Java :: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException 
Java :: how to acces every char of a String in java 
Java :: date difference in minutes java 
Java :: in java how to throw exception from function 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =