Medium Multiple Choice QuestionsΒΆ

These problems are similar to those you will see on the AP CS A exam.

5-8-1: Which of the following expressions is equivalent to !(c || d) ?






5-8-2: Which of the following is equivalent to the code segment below?

if (x > 2) x = x * 2;
if (x > 4) x = 0;





5-8-3: Which of the following is equivalent to the code segment below?

if (x > 0) x = -x;
if (x < 0) x = 0;






5-8-4: At a certain high school students receive letter grades based on the following scale: 93 or above is an A, 84 to 92 is a B, 75 to 83 is a C, and below 75 is an F. Which of the following code segments will assign the correct string to grade for a given integer score?

I.   if (score >= 93)
      grade = "A";
     if (score >= 84 && score <=92)
      grade = "B";
     if (score >=75 && score <= 83)
      grade = "C";
     if (score < 75)
      grade = "F";

II.  if (score >= 93)
      grade = "A";
     if (score >= 84)
      grade = "B";
     if (score >=75)
      grade = "C";
     if (score < 75)
      grade = "F";

III. if (score >= 93)
      grade = "A";
     else if (score >= 84)
      grade = "B";
     else if (score >=75)
      grade = "C";
     else
      grade = "F";