×

Java Math floor() Method

The floor() method of Math class returns the largest double value that is equal to a mathematical integer and is less than or equal to the argument.

Syntax:

public static double floor(double a)

Parameters:

The parameter ‘a’ represents the value.

Return Value:

The floor () method returns the largest floating-point value that is equal to a mathematical integer and is less than or equal to the argument.

Special cases of the floor() method are as follows:

  • It returns the result same as the argument, if the argument passed is equal to an integer or is a NaN or an infinity or positive zero or negative zero value

Example 1:

public class JavaMathFloorExample1 {
    public static void main(String[] args) {
        double a=10.780;
        //returns the largest double value that is less than or equal to the a
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value 0.0 = 0.0

Example 2:

public class JavaMathFloorExample2 {
    public static void main(String[] args) {
        double a=10.780/0.0d;
        //It returns the result same as 'a', if 'a' is equal to positive infinity
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value of Infinity = Infinity

Example 3:

public class JavaMathFloorExample3 {
    public static void main(String[] args) {
        double x=-110.780/0.0d;
        //It returns the result same as x, if x is equal to a Negative infinity
        System.out.println("Largest double value of "+ x+" = "+Math.floor(x));
    }
}

Output:

Largest double value of -Infinity = -Infinity

Example 4:

public class JavaMathFloorExample4 {
    public static void main(String[] args) {
        double a=0.0/0.0d;
        //It returns the result same as a, if a is equal to NaN
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value of NaN = NaN

Example 5:

public class JavaMathFloorExample5 {
    public static void main(String[] args) {
        double a=0.0d;
        //It returns the result same as a, if a is equal to zero
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value of 0.0 = 0.0

Related Topics

Java program to find frequency of characters in a string

In this article, you will understand the how to find the frequency of characters in strings by using Java programming language. Along with this, you will understand the hashing concept...

3 minutes read.

Java OCR

In this article, you will be acknowledged about what is a tesseract OCR, how it works, what are its used and advantages and disadvantages. Also, you will be able to...

4 minutes read.

How to take Array Input in Java

In this tutorial, we will learn about how to take array input in Java. So, before taking inputs let us know what an array is first. Array: An array is a collection...

10 minutes read.

Different Ways to Print Exception Message in Java

In this section, we will learn how to use various Java Throwable class methods to print exception messages. The Throwable class has the three methods listed below for printing the...

4 minutes read.

Object Definition in Java

In this article, you will be acknowledged about object in Java, its definition and how is this useful in writing the programs in Java. The comprehension of object-oriented technology depends on...

4 minutes read.

Java Queue Interface

Queue interface is a subtype of Collection interface. All methods in the Collection interface are also available in the Queue interface. It provides operations of Collection and also some additional...

2 minutes read.

Class memory in Java

Anything specifically defined in the Java code is stored either inside the heap or the stack, which is particularly significant. Stack and heap are the two kinds of memory available...

6 minutes read.

Read JSON file in Java

 To know about reading a JSON file in Java first we must know about the JSON file. JSON: JSON is “JavaScript Object Notation”. The JSON is the simple format for storing and...

3 minutes read.

Missing Number in an Arithmetic Progression in Java

Given an array that shows the elements of an orderly arithmetic progression. Find the missing number to complete the succession of elements. Example:  Input: a [ ] = {2 , 4 , 6...

3 minutes read.

Command Class in Java

We use the command class to run commands against the database. The Command class may find a set of parameter objects for use in sending values to a stored procedure...

3 minutes read.

Trimorphic numbers in Java

Wondered what the Trimorphic number is!! In this article, you can learn about what a Trimorphic number is referred to as and how to find whether a number is trimorphic...

3 minutes read.

Find the Frequency of Each Element in the Array in Java

We may count the occurrence of each element in the array of items. Maintaining one array to store the counts of each array element is one strategy for solving this issue....

3 minutes read.

Factorial of a Large Number in Java

We've already talked about a number's factorial. We must still go over the factorial of a large number separately, though. The method used to determine the factorial of a small...

8 minutes read.

Monsoon Umbrella Problem in Java

The Monsoon Umbrella problem is a classic Java programming problem used to test the skills of a programmer. The problem involves writing a program to determine the number of umbrellas...

3 minutes read.

How to Convert Timestamp to Date in Java

How to Convert Timestamp to Date in Java You can convert Timestamp to Date by using the constructor of Date class. It returns the long millisecond from Epoch (1st January 1970)...

2 minutes read.

How to use Lambda Expression in Java?

The new and significant lambda expression feature of Java was added in Java SE 8. It provides a clear and concise mechanism for describing a single method interface using an...

4 minutes read.

Java Math tan() Method

The tan() method of Java Math class returns the trigonometric tangent of the specified angle. Syntax: public static double tan(double a) Parameters: The parameter ‘a’ represents an angle measured in radians. Return Value: The tan() method...

2 minutes read.

Lambda expressions in Java

A brief introduction to Lambda expression in java In this topic, we will discuss the lambda expression in java. A lambda expression in Java is an enhanced version of an anonymous...

13 minutes read.

Merge Sort in Java

Merge Sort in Java Merge sort in Java uses the divide and conquer approach to sort the given array/ list. There are three steps involved in the merge sort. 1) Divide the...

5 minutes read.

Java Destructors

Before knowing about Java destructors, let us know about constructors. If we understand the concept of the constructor, we can easily understand about destructor and also, we will get an...

3 minutes read.