zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

Using Objects in AP Computer Science A

Question 1
Computer Science AAPConcept Practice
1 mark

Which of the following is the primary purpose of a non-void method?

Question 2
Computer Science AAPConcept Practice
1 mark

Which part of a non-void method header specifies the type of value that the method will return?

Question 3
Computer Science AAPConcept Practice
1 mark

Consider the following method definition:

java
public int calculateSum(int a, int b) {
    int sum = a + b;
}

What is the most likely error in this code?

Question 4
Computer Science AAPConcept Practice
1 mark

What should be the return type of a method that calculates the area of a square, given the side length as a double?

Question 5
Computer Science AAPConcept Practice
1 mark

Complete the following method to correctly determine if a number is prime:

java
public static boolean isPrime(int number) {
    for (int i = 2; i < number; i++) {
        if (number % i == 0) {
            // Not prime
        }
    }
    // Prime
    return _________;
}
Question 6
Computer Science AAPConcept Practice
1 mark

What will be the output of the following code?

java
public class StringModifier {
    public static String addExclamation(String str) {
        return str + "!";
    }

    public static void main(String[] args) {
        String message = "Hello";
        String excitedMessage = addExclamation(message);
        Sys...
Question 7
Computer Science AAPConcept Practice
1 mark

Consider the following method:

java
public static ArrayList<Integer> createList(int size) {
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        if (i % 2 == 0) {
            list.add(i);
        }
    }
    return list;
}

What will be returned if createList(5) is cal...

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPConcept Practice
1 mark

Identify the error in the following code:

java
public class Example {
    public int calculate(int x, int y) {
        double result = x * y;
        return result;
    }
}
Question 9
Computer Science AAPConcept Practice
1 mark

What is the issue with the following code?

java
public class MathUtils {
    public int square(int num) {
        return num * num;
        System.out.println("Calculation complete");
    }
}
Question 10
Computer Science AAPConcept Practice
1 mark

Why is it important to carefully read the method signature, especially the return type, when answering exam questions involving non-void methods?