| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
easy Solved by 3 students
Primitive Type Method Call Error
< Prev
Next >

Which of the following best explains why the ConditionError class shown below will fail to compile?

public class ConditionError {
    public static int countRecursively(int n) {
        if(n.equals(0))
            return 0;
        else
            return n + countRecursively(n - 1);
    }
    
    public static void main(String[] args) {
        System.out.println(countRecursively(5));
    }
}
A

The code incorrectly attempts to call the equals method on a primitive int, which is not allowed.

B

The base case condition is logically flawed.

C

The method countRecursively should return a boolean value.

D

The arithmetic operator in the recursive call is misused.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy