bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java Math nextAfter() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java Math nextAfter() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___.out.println(Math.nextAfter(1, 2));
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The nextAfter() method returns the floating point number adjacent to a number x in the direction of a number y.
Definition and Usage
Java Math nextAfter() Method

❮ Math Methods

Example

System.out.println(Math.nextAfter(1, 2));
System.out.println(Math.nextAfter(1, 0));
System.out.println(Math.nextAfter(0.5f, 1.0f));
System.out.println(Math.nextAfter(0.5f, 0.0f));

Definition and Usage

The nextAfter() method returns the floating point number adjacent to a number x in the direction of a number y.

If y is greater than x then it looks for the lowest possible floating point number that is greater than x. If y is less than x then it looks for the highest possible floating point number that is less than x. If y is equal to x then this method returns x. The return value for double type arguments will be closer to x than the return value for float type arguments. Syntax One of the following: public static double nextAfter(double x , double y ) public static float nextAfter(float x , double y ) Parameter Values Parameter Description x Required. The number to start from. y Required. The direction to step towards. Technical Details Returns: A double or float value representing the next floating point number from a starting point in a specified direction. Java version: 1.6+ ❮ Math Methods

The return value for double type arguments will be closer to x than the return value for float type arguments. Syntax One of the following: public static double nextAfter(double x , double y ) public static float nextAfter(float x , double y ) Parameter Values Parameter Description x Required. The number to start from. y Required. The direction to step towards. Technical Details Returns: A double or float value representing the next floating point number from a starting point in a specified direction. Java version: 1.6+ ❮ Math Methods

The return value for double type arguments will be closer to x than the return value for float type arguments.

One of the following

public static double nextAfter(double
x , double
y )
public static float nextAfter(float
x , double
y )

Parameter Values

ParameterDescription
xRequired. The number to start from.
yRequired. The direction to step towards.

Technical Details

Returns:A double or float value representing the next floating point number from a starting point in a specified direction.
Java version:1.6+

Previous

Java Math negateExact() Method

Next

Java Math nextDown() Method