Primitive Type Arithmetic Calculation
Consider the following method, which is intended to convert a given number of hours and minutes into a total number of seconds.
public static int convertToSeconds(int hours, int minutes) {
/* missing statement */
return totalSeconds;
}
For example, convertToSeconds(1, 30) should return 5400, and convertToSeconds(2, 15) should return 8100. Which of the following code segments can replace /* missing statement */ so that the method works as intended?
A
int totalSeconds = (hours + minutes) * 60;
B
int totalSeconds = Math.abs(hours * 60 - minutes) * 60;
C
int totalSeconds = hours * 60 * 60 + minutes * 60;
D
int totalSeconds = (int) (hours * minutes * 60);
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | varunrajaram1 | 1 | 1 | 0m 00s | 100 |
| #2 | l.alzahrani04 | 1 | 1 | 0m 00s | 100 |
| #3 | liuwilliam072410 | 1 | 1 | 0m 21s | 79 |
| #4 | patrickmeijer009 | 1 | 1 | 0m 29s | 71 |
| #5 | yeee5864 | 1 | 1 | 0m 30s | 70 |
| #6 | 6test6ing6 | 2 | 2 | 2m 13s | 67 |
| #7 | leftoverjluck | 1 | 1 | 0m 37s | 63 |
| #8 | raufyildirim95 | 1 | 1 | 0m 46s | 54 |
| #9 | 7017046 | 1 | 1 | 0m 46s | 54 |
| #10 | kshiva2009m | 1 | 1 | 0m 52s | 48 |
Items per page:
10
1 – 10 of 26
APFIVE