Question: In the following code segment, x and y are properly declared and initialized int variables whose 1 Mark for Review values are positive. The code
In the following code segment, x and y are properly declared and initialized int variables whose 1 Mark for Review values are positive. The code segment is intended to print the average of x and y . For example, if x is 10 and y is 5 , the code segment is intended to print 7.5 . Which of the following best describes the error, if any, in the code segment? int sum = x + y; A There is no error; the code segment works as intended. double average = (double) (sum / 2) ; System. out . printIn (average) ; B In the expression (double) (sum / 2) , the cast to double is applied too late, so the average will be less than the expected result for even values of B sum . C In the expression (double) (sum / 2) , the cast to double is applied too late, so the average will be less than the expected result for odd values of sum . D In the expression (double) (sum / 2) , the cast to double is applied too late, so the average will be greater than the expected result for odd values of sum
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
