nextAfter(): This method is available in the Math class of Java.
Syntax:
float java.lang.Math.nextAfter(float start, double direction)
This method takes two arguments, one of type float and another of type double as its parameter. It returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal a value equivalent to the second argument is returned.
Special cases:
1. If either argument is a NaN, then NaN is returned.
2. If both arguments are signed zeros, a value equivalent to direction is returned.
3. If start is ±Float.MIN_VALUE and direction have a value such that the result should have a smaller magnitude, then zero with the same sign as a start is returned.
4. If the start is infinite and direction has a value such that the result should have a smaller magnitude, Float.MAX_VALUE with the same sign as the start is returned.
5. If start is equal to ± Float.MAX_VALUE and direction have a value such that the result should have a larger magnitude, an infinity with the same sign as the start is returned.
Parameters: Two parameters are required for this method.
start: starting floating-point value.
direction: value indicating which of start's neighbors or start should be returned.
Returns: The floating-point number adjacent to start in the direction of the direction.
For Example:
Math.nextAfter(199.991, 1888) = > It returns 199.99101
Approach
Java
public class NextAfterFloat {public static void main(String[] args) {float start = (float) 199.991;double direction = 1888;System.out.println(Math.nextAfter(start, direction));}}
Output:
199.99101
No comments:
Post a Comment