Skip to the content.

CSA

CSA Week 0 Week 1 Week 2 Week 3 Final Week 5 Week 6 Study
Week 7

Week 6 - Ticket

2020 Practice Exam 1 MCQ

Overall Score: 26/40

Question 6: Which of the following expressions evaluate to 3.5 ?

  1. (double) 2 / 4 + 3
  2. (double) (2 / 4) + 3
  3. (double) (2 / 4 + 3)

Question 7: Consider the following code segment.

int num = /* initial value not shown */;
boolean b1 = true;
if (num > 0) {
    if (num >= 100) {
        b1 = false;
    }
}
else {
    if (num >= -100) {
        b1 = false;
    }
}

Which of the following statements assigns the same value to b2 as the code segment assigns to b1 for all values of num?

Question 9: Consider the following code segment.

ArrayList<Integer> numList = new ArrayList<Integer>();
numList.add(3);
numList.add(2);
numList.add(1);
numList.add(1, 0);
numList.set(0, 2);
System.out.print(numList);

What is printed by the code segment?

Question 10: Consider the following method.

public static void printSome(int num1, int num2) {
    for (int i = 0; i < num1; i++) {
        if (i % num2 == 0 && i % 2 == 0) {
            System.out.print(i + " ");
        }
    }
}

Which of the following method calls will cause “0 10 “ to be printed?

Question 12: Which of the following can replace /* missing condition */ so that the printDetails method CANNOT cause a run-time error?

borrower is a variable of Book Class
data type of borrower is Person (custom class)
  1. !borrower.equals(null)
  2. borrower != null
  3. borrower.getName() != null

Question 13: Assume that a, b, and c are boolean variables that have been properly declared and initialized. Which of the following boolean expressions is equivalent to !(a && b) || c?

Question 14: The following categories are used by some researchers to categorize zip codes as urban, suburban, or rural based on population density.

I.

String cat;
if (density > 3000) {
    cat = "urban";
}
else if (density > 999) {
    cat = "suburban";
}
else {
    cat = "rural";
}
return cat;

II.

String cat;
if (density > 3000) {
    cat = "urban";
}
if (density > 999) {
    cat = "suburban";
}
cat = "rural"; 
return cat;

III.

if (density > 3000) {
   return "urban";
}
if (density > 999) {
   return "suburban";
}
return "rural";

Question 27: Consider the following statement. Assume that a and b are properly declared and initialized boolean variables.

boolean c = (a && b) || (!a && b);

Under which of the following conditions will c be assigned the value false?

Question 28: Consider the following method.

public static String abMethod(String a, String b) {
    int x = a.indexOf(b);
    while (x >= 0) {
        a = a.substring(0, x) + a.substring(x + b.length());
        x = a.indexOf(b);
    }
    return a;
}

What, if anything, is returned by the method call abMethod(“sing the song”, “ng”)?

Question 31: Consider an integer array nums, which has been properly declared and initialized with one or more values. Which of the following code segments counts the number of negative values found in nums and stores the count in counter?

I.

int counter = 0;
int i = -1;
while (i <= nums.length - 2)
{
   i++;
   if (nums[i] < 0)
   {
      counter++;
   }
}

II.

int counter = 0;
for (int i = 1; i < nums.length; i++)
{
   if (nums[i] < 0)
   {
      counter++;
   }
}

III.

int counter = 0;
for (int i : nums)
{
   if (nums[i] < 0)
   {
      counter++;
   }
}

Question 33: Consider the following code segment.

String[][] letters = /* array implementation not shown */;
// A B C D
// E F G H
// I J K L

for (int col = 1; col < letters[0].length; col++) {
    for (int row = 1; row < letters.length; row++) {
        System.out.print(letters[row][col] + " ");
    }
    System.out.println();
}

What is printed as a result of executing this code segment?

Question 38 - 40:

2020 Practice Exam 1 FRQ

FRQ2
Image Preview
FR4
Image Preview