Verityprep
Question Bank · Unit 1

AP® Computer Science A Using Objects and Methods Practice Questions

Work through AP Computer Science A practice questions on Using Objects and Methods, 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 151–160 of 776
  1. 151
  2. 152
  3. 153
  4. 154
  5. 155
  6. 156
  7. 157
  8. 158
  9. 159
  10. 160

Question 151

Free response Using Objects

Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi".

makeAbba("Hi", "Bye") → "HiByeByeHi"
makeAbba("Yo", "Alice") → "YoAliceAliceYo"
makeAbba("What", "Up") → "WhatUpUpWhat"

Complete the method makeAbba below:

public String makeAbba(String a, String b) {
}
The answer and the full solution open in a window.

Question 152

Free response Using Objects

The web is built with HTML strings like "<i>Yay</i>" which draws Yay as italic text. In this example, the "i" tag makes <i> and </i> which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "<i>Yay</i>".

makeTags("i", "Yay") → "<i>Yay</i>"
makeTags("i", "Hello") → "<i>Hello</i>"
makeTags("cite", "Yay") → "<cite>Yay</cite>"

public String makeTags(String tag, String word) {
}
The answer and the full solution open in a window.

Question 153

Free response Using Objects

Given an "out" string length 4, such as "<<>>", and a word, return a new string where the word is in the middle of the out string, e.g. "<<word>>". Note: use str.substring(i, j) to extract the String starting at index i and going up to but not including index j.

makeOutWord("<<>>", "Yay") → "<<Yay>>"
makeOutWord("<<>>", "WooHoo") → "<<WooHoo>>"
makeOutWord("[[]]", "word") → "[[word]]"

Complete the method makeOutWord below:

public String makeOutWord(String out, String word) {
}
The answer and the full solution open in a window.

Question 154

Free response Using Objects
Given a string, return a new string made of 3 copies of the last 2 chars of the original string. 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 155

Free response Using Objects
Given a string, return the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 156

Free response Using Objects
Given a string of even length, return the first half. So the string "WooHoo" yields "Woo". firstHalf("WooHoo")…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 157

Free response Using Objects
Given a string, return a version without the first and last char, so "Hello" yields "ell". 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 158

Free response Using Objects
Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 159

Free response Using Objects
Given 2 strings, return their concatenation, except omit the first char of each. The strings will be at least length 1. nonStart("Hello", "There") →…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 160

Free response Using Objects
Given a string, return a "rotated left 2" version where the first 2 chars are moved to the end. 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 151 of 776
Page 16 of 78