Java Data Type Tutorial - Java Math.nextAfter(double start, double direction)








Syntax

Math.nextAfter(double start, double direction) has the following syntax.

public static double nextAfter(double start,  double direction)

Example

In the following code shows how to use Math.nextAfter(double start, double direction) method.

/*from w w  w.jav a  2 s  .c  o m*/

public class Main {

   public static void main(String[] args) {
      double x = 123456.7;
      double y = -123.45;


      // print the next number for x towards y
      System.out.println("Math.nextAfter(" + x + "," + y + ")="
              + Math.nextAfter(x, y));

      // print the next number for y towards x
      System.out.println("Math.nextAfter(" + y + "," + x + ")="
              + Math.nextAfter(y, x));

   }
}

The code above generates the following result.