Home >>Java Math Methods >Java Math.nextAfter() method
The Math.nextAfter() in Java Math is used to returns, in the direction of the second argument, the floating point number adjacent to the first argument. If both the first argument and the second argument are equivalent then the second argument returns this method.
public static double nextAfter(double a, double b) public static float nextAfter(float a, double b)
a = This parameter is used to starting floating-point value
b = This parameter is used to the direction value indicating which of start's neighbors or start should be returned
It is used to returns the floating-point number adjacent to start(a) in the direction of b.
public class Main
{
public static void main(String[] args)
{
double x = 4342.08;
double y = 432.232;
System.out.println(Math.nextAfter(x, y));
System.out.println(Math.nextAfter(y, x));
}
}
public class MyClass
{
public static void main(String[] args)
{
float x = 123.324f;
double y = 976.03;
System.out.println(Math.nextAfter(x, y));
}
}