| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice TestPractice Test
About Exam
medium Solved by 8 students
String Pair Swapping Loop
< Prev
Next >

Consider the following transform method.

public static String transform(String str) {
  String transformed = "";
  for (int i = 0; i < str.length() - 1; i += 2) {
    transformed += str.substring(i + 1, i + 2) + str.substring(i, i + 1);
  }
  if (str.length() % 2 != 0) {
    transformed += str.substring(str.length() - 1);
  }
  return transformed;
}

What is returned by the call transform("1234567")?

A

“2143567”

B

“214356”

C

“2135467”

D

“2143657”

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1hitrishabhatia13 0m 00s 80
#2bommasam00011 0m 23s 77
#3y.seong202712 1m 23s 7
#4Pelisx11 2m 54s -74
#5suhanakochhar00601 4m 19s -269
#6midnightasdark13 7m 58s -398
Items per page:
10
1 – 6 of 6
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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