Discover answers to your most pressing questions at Westonci.ca, the ultimate Q&A platform that connects you with expert solutions. Experience the ease of finding accurate answers to your questions from a knowledgeable community of professionals. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

BJP4 Self-Check 7.21: swapPairs

Write a method named swapPairs that accepts an array of strings as a parameter and switches the order of values in a pairwise fashion. Your method should switch the order of the first two values, then switch the order of the next two, switch the order of the next two, and so on.

PLEASE HELP DUE AT 11:59


Sagot :

Answer:

public static void swapPairs(ArrayList strList)

{

 for(int i = 0; i < strList.size() - 1; i += 2)

 {

  String temp1 = strList.get(i);

  String temp2 = strList.get(i + 1);

  strList.set(i, temp2);

  strList.set(i + 1, temp1);

 }

}

Explanation: