Verityprep
Question Bank

AP® Computer Science A Practice Questions

Work through AP Computer Science A practice questions unit by unit, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Questions 161–170 of 3,140
  1. 161
  2. 162
  3. 163
  4. 164
  5. 165
  6. 166
  7. 167
  8. 168
  9. 169
  10. 170

Question 161

Free response Unit 1: Using Objects and Methods
Given a string, return a "rotated right 2" version where the last 2 chars are moved to the start. The string length will be at least 2.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 162

Free response Unit 1: Using Objects and Methods
Given a string, return a string length 1 from its front, unless front is false, in which case return a string length 1 from its back. The string will be…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 163

Free response Unit 1: Using Objects and Methods
Given a string, return a version without both the first and last char of the string. The string may be any length, including 0.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 164

Free response Unit 1: Using Objects and Methods
Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string length will be at least 2.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 165

Free response Unit 1: Using Objects and Methods
Given a string, return true if it ends in "ly". endsLy("oddly") → true endsLy("y") → false…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 166

Free response Unit 1: Using Objects and Methods
Given a string and an int n, return a string made of the first and last n chars from the string. The string length will be at least n. nTwice("Hello",…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 167

Free response Unit 1: Using Objects and Methods
Given a string and an index, return a string length 2 starting at the given index. If the index is too big or too small to define a string length 2, use the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 168

Free response Unit 1: Using Objects and Methods
Given a string of odd length, return the string length 3 from its middle, so "Candy" yields "and". The string length will be at…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 169

Free response Unit 1: Using Objects and Methods
Given a string, return true if "bad" appears starting at index 0 or 1 in the string, such as with "badxxx" or "xbadxx" but not "xxbadxx". The string may be any…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 170

Free response Unit 1: Using Objects and Methods
Given a string, return a string length 2 made of its first 2 chars. If the string length is less than 2, use '@' for…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 161 of 3,140
Page 17 of 314