Java Arithmetic Expression Evaluation
Which of the following statements can replace the /* missing statement */ so that calculateExpression works as intended?
Consider the method calculateExpression, which is intended to compute the result of a mathematical expression involving addition, multiplication, and division.
For example, the following scenarios demonstrate the expected behavior of calculateExpression:
calculateExpression(5, 4, 2) = 10.0
calculateExpression(6, 3, 2) = 9.0
The current implementation of calculateExpression is incomplete:
public static double calculateExpression(int a, int b, int c) {
/* missing statement */
return result;
}
Which of the following statements can replace the /* missing statement */ so that calculateExpression works as intended?
A
double result = a * (b - c) + a / c;
B
double result = (a * b) / c;
C
double result = a + b * c - (a / c);
D
double result = a / b * c + a;
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | 108185265 | 3 | 3 | 0m 18s | 282 |
| #2 | lsj08030922 | 1 | 1 | 0m 42s | 58 |
| #3 | sarah.alyahya90tt | 0 | 1 | 0m 00s | -10 |
| #4 | patrickmeijer009 | 1 | 1 | 3m 43s | -123 |
| #5 | y.seong2027 | 1 | 1 | 4m 11s | -151 |
| #6 | shelter2002004 | 1 | 1 | 6m 10s | -270 |
APFIVE