# StrictMath nextAfter() Method in Java

- The
**nextAfter(**is the inbuilt method of StrictMath class in Java which is used to get the float number, adjacent to the*double start, double direction*)*start*in the direction of the second argument*direction*. This method gives rise to few conditions depending on the type and variation of parameters.- The result is the second argument when both the arguments are equal.
- The result is NaN when any one of the arguments is a NaN.
- The result is the
*direction*without any change when both arguments are signed zeros. - The result is a zero with the same sign as
*start*when*start*is*±Double.MIN_VALUE*and*direction*has a value such that the result has a smaller magnitude. - The result is the
*Double.MAX_VALUE*with the same sign as*start*when*start*is infinite and*direction*has a value such that the result should have a smaller magnitude. - The result is an infinity with same sign of
*start*when*start*is equal to*±Double.MAX_VALUE*and*direction*has a value such that the result should have a larger magnitude.

**Syntax:**public static double nextAfter(

*double start, double direction*)**Parameters:**The method accepts two parameters:*start:*This is of double type which refers to the starting floating-point value.*direction:*This is of double type and refers to the value which indicates whether the start’s neighbors or start should be returned.

**Return Value:**The method retuns the floating point number that is adjacent to*start*in the direction of*direction*.

**Examples :**Input: start = 72.74d direction = 1.2d Output: 72.73999999999998

Below programs illustrate the java.lang.StrictMath.nextAfter() method:

`// Java program to demonstrate nextAfter()`

`import`

`java.lang.*;`

`public`

`class`

`Geeks {`

`public`

`static`

`void`

`main(String[] args)`

`{`

`double`

`start =`

`23`

`.62d, direction =`

`0`

`.0d;`

`double`

`result = StrictMath.nextAfter(start, direction);`

`System.out.println(`

`"The NextAfter is = "`

`+ result);`

`result = StrictMath.nextAfter(start,`

`9`

`.2d);`

`System.out.println(`

`"The NextAfter is = "`

`+ result);`

`result = StrictMath.nextAfter(direction,`

`7`

`.2d);`

`System.out.println(`

`"The NextAfter is ="`

`+ result);`

`// Returns 0 if both arguments are zero`

`result = StrictMath.nextAfter(direction,`

`0`

`.0d);`

`System.out.println(`

`"The NextAfter is ="`

`+ result);`

`}`

`}`

*chevron_right**filter_none***Output:**The NextAfter is = 23.619999999999997 The NextAfter is = 23.619999999999997 The NextAfter is =4.9E-324 The NextAfter is =0.0

- The
**nextAfter(**is an inbuilt method of StrictMath class in Java which is used to get the float number which is adjacent to the*float start, double direction*)*start*in the direction of the second argument*direction*.- The result is the second argument when both the arguments are equal.
- The result is NaN when any one of the arguments is a NaN.
- The result is the
*direction*without any change when both arguments are signed zeros. - The result is a zero with the same sign as
*start*when*start*is ±Float.MIN_VALUE and*direction*has a value such that the result should have a smaller magnitude. - The result is the Float.MAX_VALUE with the same sign as
*start*when*start*is infinite and*direction*has a value such that the result should have a smaller magnitude. - The result is an infinity with same sign of
*start*when*start*is equal to ±Float.MAX_VALUE and*direction*has a value such that the result should have a larger magnitude.

**Syntax:**public static double nextAfter(

*float start, double direction*)**Parameters:**The method accepts two parameters:*start:*This is of float type which refers to the starting floating-point value.*direction:*This is of double type and refers to the value which indicates whether the start’s neighbors or start should be returned.

**Return Value:**The method retuns the floating point number, adjacent to*start*in the direction of*direction*.**Examples :**Input: start = 22.2f direction = 0.0d Output: 22.20000076293945

Below programs illustrate the java.lang.StrictMath.nextAfter() method:

`// Java program to demonstrate nextAfter()`

`import`

`java.lang.*;`

`public`

`class`

`Geeks {`

`public`

`static`

`void`

`main(String[] args)`

`{`

`double`

`start =`

`42`

`.9f;`

`double`

`direction =`

`0`

`.0d;`

`double`

`result = StrictMath.nextAfter(start, direction);`

`System.out.println(`

`"The NextAfter is = "`

`+ result);`

`result = StrictMath.nextAfter(start,`

`9`

`.2d);`

`System.out.println(`

`"The NextAfter is = "`

`+ result);`

`result = StrictMath.nextAfter(direction,`

`7`

`.2d);`

`System.out.println(`

`"The NextAfter is ="`

`+ result);`

`// Returns 0 if both arguments is zero`

`result = StrictMath.nextAfter(direction,`

`0`

`.0d);`

`System.out.println(`

`"The NextAfter is ="`

`+ result);`

`}`

`}`

*chevron_right**filter_none***Output:**The NextAfter is = 42.9000015258789 The NextAfter is = 42.9000015258789 The NextAfter is =4.9E-324 The NextAfter is =0.0

## Recommended Posts:

- Java Math nextAfter() method with Example
- StrictMath sin() Method in Java
- StrictMath pow() Method in Java
- StrictMath exp() Method in Java
- StrictMath tan() Method in Java
- StrictMath log() Method In Java
- StrictMath floor() Method in Java
- StrictMath atan2() Method in Java
- StrictMath hypot() Method in Java
- StrictMath acos() Method in Java
- StrictMath scalb() Method in Java
- StrictMath cosh() Method in Java
- StrictMath min() Method in Java with Examples
- StrictMath rint() Method in Java
- StrictMath round() method in Java

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.