| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice Test
Share
medium Solved by 8 students
Recursive String Method Trace
< Prev
Next >

Consider the following recursive method.

public boolean isNestedProperly(String s) {
  if (s.isEmpty())
    return true;
  else if (s.charAt(0) == 'x' && s.charAt(s.length() - 1) == 'x')
    return isNestedProperly(s.substring(1, s.length() - 1));
  else
    return false;
}

What is returned as a result of the call isNestedProperly("xxxx")?

A

The function returns nothing; there is a compilation error

B

The function throws an exception

C

false

D

true

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1richa.tuli23 3m 42s -32
#2suhanakochhar00611 3m 21s -101
#3singhris00014 3m 45s -155
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy