×

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 callable example

What is callable in Java? Callable is an interface that is present in Java. There are two methods for constructing threads: one is to inherit the Thread class, while the other...

3 minutes read.

Package naming convention in Java

It is conceivable that many programmers will use the same name for various types, given that Java programmers from all over the world create classes and interfaces. For illustration, suppose...

4 minutes read.

Java Virtual Machine (JVM)

JVM is a virtual runtime environment to execute Java byte codes. The JVM doesn’t understand the keywords we used to write code. That is why it is converted into bytecode. It controls the...

3 minutes read.

Java String compareTo() Method

compareTo() method is used to compare the two specified Strings based on the alphabetical order(lexicographical order) of their characters.It returns positive number ,negative number or 0 Syntax: public int compareTo(String anotherString) Parameters: anotherString: the...

2 minutes read.

Difference between Static and Instance Methods in Java

Static Method in Java The static technique has a place with the class as opposed to the object of the course. These are intended to be divided between every one of...

10 minutes read.

Java Keywords

Java Keywords The particular words which are used in java programming language that act like a key or important words to write a code are called java keywords. Java Keywords are...

4 minutes read.

Manachers Algorithm in Java

Here, we'll go over the four scenarios once more in an effort to approach them differently and use the same strategy. The values of (centerRightPosition - currentRightPosition) and LPS length at...

3 minutes read.

Java Read File

Java provides its users with many ways of reading a file. To read a text file, you can use a FileReader, BufferedReader, or Scanner. Each utility offers something special for...

6 minutes read.

Exception Handling Program in Java

Exception Handling Program in Java Exception means something that is abnormal. In Java, an exception is treated as a problem that disrupts the normal flow of the program. An exception leads...

7 minutes read.

Java RandomAccessfile

Writing and reading to random access files are done using this class. An array of many bytes is how a random access file operates. By changing the implied file pointer...

3 minutes read.

Java Math tanh() Method

The tanh() method of Java Math class returns the hyperbolic tangent of the specified double value. Syntax: public static double tanh(double x) Parameters: The parameter ‘x’ represents the number whose hyperbolic tangent is to...

2 minutes read.

Addition Program in Java

Addition Program in Java We can perform the addition (sum) of two or more numbers by using the arithmetic operator (+). To write an addition program in Java, one must understand...

3 minutes read.

Java Math max() Method

The max() method of Math class returns the greater of two arguments. The arguments can be of double, float, int or long data type. Syntax: public static double max(double a, double b)public...

2 minutes read.

Java Generics Questions

Introduction We'll walk through a few real-world examples of interview questions and responses for Java generics in this article. Java 5 saw the debut of the fundamental idea of generics. Due to...

9 minutes read.

Stable Marriage Problem in Java

Given N men and N women, the Stable Marriage Problem asks you to match up the men and women in such a way that there are never any two people...

6 minutes read.

PriorityQueue in Java

PriorityQueue in Java A PriorityQueue is a member of the Java Collection Framework and is used when the values are needed to be processed based on priority. Priority queue operates similar to...

8 minutes read.

Java String isEmpty() method

Java String isEmpty() method checks whether current String is empty or not. Syntax: public boolean isEmpty() Returns It returns true, if length of String is 0 otherwise false. Java String isEmpty() method example 1    ...

1 minute read.

Check the presence of Substring in a String in java

In java, the string can be treated as class and datatype. The string contains words and numbers but should be in double-quotes. Example: ” Omsairam” Substring The part of the string is called...

2 minutes read.

Java Extends keyword

Extends Extends is a keyword which is completely depended on the concept of the inheritance of the java programming language.To understand about of the keyword, we need to learn the concept...

3 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.