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.


//w ww.  j  av  a2  s  . c om

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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable