Consider the following code segment: if (Y < 0) {X = -X; Y = -Y;} Z = 0; while…
KVS TGT/PGT 2017Kendriya Vidyalaya Sangathan 2017
Consider the following code segment: if (Y < 0) {X = -X; Y = -Y;} Z = 0; while (Y > 0) {Z = Z + X; Y = Y - 1;} Assume that X, Y and Z are integer variables , and that X and Y have been initialized . Which of the following best describes what this code does?
- A.
Sets Z to be the product X * Y
- B.
Sets Z to be the sum X + Y
- C.
Sets Z to be the absolute value of X
- D.
Sets Z to be the value of Y
Attempted by 333 students.
Sign up free to check your answer
Sign up freeLoading lesson…

