Wednesday, July 3, 2024
HomeLanguagesJavaCalendar getLeastMaximum() method in Java with Examples

Calendar getLeastMaximum() method in Java with Examples

The getLeastMaximum(int calndr_field) method in Calendar class is used to return the lowest maximum value for the given calendar field(int calndr_field) of this Calendar instance.

Syntax:

public abstract int getLeastMaximum(int calndr_field)

Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to be operated upon.

Return Value: The method returns the lowest maximum value of this calendar field.

Below programs illustrate the working of getLeastMaximum() Method of Calendar class:
Example 1:




// Java code to illustrate
// getLeastMaximum() method
  
import java.util.*;
  
public class Calendar_Demo {
    public static void main(String args[])
    {
  
        // Creating a calendar
        Calendar calndr = Calendar.getInstance();
  
        // Getting the required months
        System.out.println("Required Months: "
                           + calndr.get(Calendar.MONTH));
  
        // Getting the lowest maximum month
        int low_max = calndr.getLeastMaximum(Calendar.MONTH);
  
        // Displaying the results
        System.out.println("The Lowest"
                           + " Maximum months: " + low_max);
    }
}


Output:

Required Months: 1
The Lowest Maximum months: 11

Example 2:




// Java code to illustrate
// getLeastMaximum() method
  
import java.util.*;
  
public class Calendar_Demo {
    public static void main(String args[])
    {
  
        // Creating a calendar
        Calendar calndr = new GregorianCalendar(2018, 6, 10);
  
        // Getting the required months
        System.out.println("Required Months: "
                           + calndr.get(Calendar.MONTH));
  
        // Getting the lowest maximum month
        int low_max = calndr.getLeastMaximum(Calendar.MONTH);
  
        // Displaying the results
        System.out.println("The Lowest"
                           + " Maximum months: " + low_max);
    }
}


Output:

Required Months: 6
The Lowest Maximum months: 11

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getLeastMaximum-int-

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments