×

Java Math nextDown() Method

The nextDown() method of Math class returns the floating-point number adjacent to the argument in direction of the negative infinity.

Syntax:

  1. public static double nextDown (double d)
  2. public static float nextDown (float f)

Parameters:

The parameters ‘d’ and ‘f’ represent the starting floating-point values.

Return Value:

The nextDown () method returns the floating-point number which is closer to negative infinity.

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

  • It returns NaN, is the argument passed is NaN.
  • It returns negative infinity, if the argument is negative infinity.
  • It returns –Double.MIN_VALUE, is the argument is zero.

Example 1:

public class JavaMathNextDownExample1 {
    public static void main(String[] args) {
        float f = 123.78f;
        // returns the floating-point number which is closer to negative infinity
        System.out.println("Floating-point number : "+Math.nextDown(f));
    }
}

Output:

Floating-point number : 123.77999

Example 2:

public class JavaMathNextDownExample2 {
    public static void main(String[] args) {
        Double d = -0d;
        // returns the floating-point number which is closer to negative infinity
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : -4.9E-324

Example 3:

public class JavaMathNextDownExample3 {
    public static void main(String[] args) {
        Double d = Double.NaN;
        //returns NaN, is the argument passed is NaN.
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : NaN

Example 4:

public class JavaMathNextDownExample4 {
    public static void main(String[] args) {
        Double d = Double.NEGATIVE_INFINITY;
        // returns negative infinity, if the argument is negative infinity
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : -Infinity

Example 5:

public class JavaMathNextDownExample5 {
    public static void main(String[] args) {
        Double d = 0.0d;
        //returns –Double.MIN_VALUE, is the argument is zero.
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : -4.9E-324

Related Topics

What is anagram in Java?

In this section will explain what an anagram is in Java and demonstrate how to determine whether or not a text is an anagram. In Java interviews, the anagram Java...

4 minutes read.

Recursion Program in Java

The recursion program in Java demonstrates the usage of recursion. The process by which a function/ method calls itself, again and again, is called recursion. Each recursive call is pushed...

10 minutes read.

Sleeping Barber Problem in Java

The barbershop in this issue has one barber, one barber chair, and N chairs for customers in the waiting area. We may demonstrate the issue by keeping with the original...

6 minutes read.

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 Math with Methods and Examples

Java Math class contains various methods for performing math operations like min(), max(), avg() and various trigonometric functions like sin(), cos(), tan() etc. Methods: The java.lang.Math class contains various methods for performing...

5 minutes read.

Median Of Stream Of Running Integers in Java

An integer array is given to us. Compute the median of the elements traversed so far in the input array. For the sake of simplicity, assume that there are no...

10 minutes read.

How to Convert String to Object in Java

How to Convert String to Object in Java The Object is the super class of all classes. So you can assign a string to Object directly. There are two methods to...

3 minutes read.

How to Convert Binary to Decimal in Java

How to Convert Binary to Decimal in Java There are two methods to convert binary to decimal. Using Integer.parseInt() method Using user-defined logic Using Integer.parseInt() method The parseInt() is a static method of...

2 minutes read.

How to create a mirror image of a 2D array in Java

Problem Statement We have provided a list of m x n. here m indicates rows, and n indicates columns). Printing the fresh matrices should result in a mirror reflection of an...

2 minutes read.

How to Convert Decimal to Binary in Java

How to Convert Decimal to Binary in Java There are two methods to convert Decimal to Binary. Using toBinaryString() method Using user-defined logic Using Integer.toBinaryString() The toBinaryString() is a static method of Integer...

2 minutes read.

Java Generate Random String

Java Generate Random String In this tutorial, we will learn about to generate random string in Java. Random generation strings mean any string will be generated, which does not follow any...

7 minutes read.

Collection Programs in Java

Collection Programs in Java Collection in Java provides a way to manipulate or store a group of objects. Each object in a collection is called element. Collection programs in Java mainly...

4 minutes read.

Java String length() method

Java String length() method returns length of the characters in a String. Syntax: public int length() Returns It returns length of the characters Java String length() method example 1          public class JavaStringLengthEx1  ...

1 minute read.

Difference between C, C++, java

C Language: C language is a procedure oriented language. It has been invented by Dennis Ritchie in the year 1970. It is one of the computer programming language. The purpose of...

3 minutes read.

Java Null Keyword

Null is a term that is only used for literal values in Java. Although it appears to be a term, it is a literal opposite of true and false. Java's...

3 minutes read.

Trim Method in String Java

What is a String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java programming language. “String” is a...

3 minutes read.

Reserved Keywords in Java

In Java, a reserved term is used as a code key called a keyword. Because they are predefined, these terms cannot be used for anything else. They cannot serve as...

3 minutes read.

Round Robin Scheduling Program in Java

A CPU scheduling technique is known as Round Robin (RR). Additionally, network schedulers employ it. It was created specifically for a time-sharing system. The temporal slicing scheduling algorithm is another...

4 minutes read.

How to resolve Illegal state exceptions in Java

What is IllegalStateException? When a method is called at the incorrect time, a runtime exception called an IllegalStateException is raised in Java. This exception is utilized to show that a method...

3 minutes read.

How to Convert boolean to String in Java

How to Convert boolean to String in Java There are two methods to convert boolean to String. Using valueOf(boolean) method Using toString(boolean) method For both the above methods, if the passes Boolean...

2 minutes read.