Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 7 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

“2143657”

C

“2135467”

D

“214356”

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

Question Leaderboard

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

AI Tutor

How can I help?

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