Absolute Value and Casting to Round
Assume that the double variable dnum has been properly declared and initialized. Which of the following expressions correctly computes the absolute value of dnum, rounded to the nearest integer?
A
Math.abs((int)dnum - 0.5)
B
(int) Math.abs(dnum + 0.5)
C
(int) (Math.abs(dnum) + 0.5)
D
(int) Math.abs(dnum - 0.5)
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | braydenchoi1111 | 1 | 1 | 0m 00s | 100 |
| #2 | busemagngr | 1 | 1 | 0m 33s | 67 |
| #3 | aaaa1 | 0 | 1 | 0m 01s | -11 |
| #4 | demosolasis1 | 0 | 1 | 0m 52s | -62 |
| #5 | parth.taur227 | 0 | 1 | 1m 03s | -73 |
| #6 | richa.tuli | 1 | 1 | 4m 03s | -143 |
| #7 | lsj08030922 | 1 | 3 | 2h 13m | -7,927 |
Items per page:
10
1 – 7 of 7
