Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java Math rint() 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.rint(0.5));3Order
Put the learning moves in the order that makes the concept easiest to apply.
The rint() method rounds a number to the nearest integer.
Definition and Usage
Java Math rint() Method
❮ Math Methods
Example
System.out.println(Math.rint(0.5));
System.out.println(Math.rint(1.5));
System.out.println(Math.rint(5));
System.out.println(Math.rint(5.1));
System.out.println(Math.rint(-5.1));
System.out.println(Math.rint(-5.9));Definition and Usage
The rint() method rounds a number to the nearest integer. If there are two integers that are equally close to the number then the even integer will be returned.
Note
This method is very similar to round() . The main differences between rint() and round() are:
- round() returns long or int data types while rint() returns a double .
- When the decimal part of the number is exactly 0.5, rint() returns the nearest even integer while round() returns the highest of the two nearest integers
Syntax
public static double rint(double
number )Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A number to round. |
Technical Details
| Returns: | A double value representing the nearest integer to a number. |
|---|---|
| Java version: | Any |