id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

andersoniii.edwin@cusd80.com > swapPairs
prev  |  next  |  chance

Write a method swapPairs that accepts an array of strings as a parameter, returns a new array of strings which swaps the order of values in a pairwise fashion. Your method should switch the order of the first two String values, then switch the order of the next two, switch the order of the next two, and so on... For example, if the array has these strings: {four score and seven years ago} - the new array would be [score four seven and ago years] If the parameter array is empty - return an empty array. In an odd length string array the last element would not be moved.


swapPairs([""]) → [""]
swapPairs(["four", "score", "and", "seven", "years", "ago"]) → ["score", "four", "seven", "and", "ago", "years"]
swapPairs(["to", "be", "or", "not", "to", "be", "hamlet"]) → ["be", "to", "not", "or", "be", "to", "hamlet"]

...Save, Compile, Run (ctrl-enter)

public String[] swapPairs(String[] a) }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 140

Copyright Nick Parlante 2017 - privacy