Here are some examples of negative numbers rounded to the nearest integer.
Negative real number |
Rounded to nearest integer |
−3.5 |
-4 |
−8.97 |
-9 |
−5.0 |
-5 |
−2.487 |
-2 |
−0.2 |
0 |
Refer to the declaration
double d = -4.67;
Which of the following correctly rounds d to the nearest integer?
(A) int rounded = Math.abs(d);
(B) int rounded = (int) (Math.random() * d);
(C) int rounded = (int) (d - 0.5);
(D) int rounded = (int) (d + 0.5);
(E) int rounded = Math.abs((int) (d - 0.5));