1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
emmainna [20.7K]
3 years ago
9

Write a method called swapPairs that switches the order of values in an ArrayList of strings in a pairwise fashion. Your method

should switch the order of the first two values, then switch the order of the next two, then the next two, and so on. If the number of values in the list is odd, the method should not move the final element. For example, if the list initially stores ["to", "be", "or", "not", "to", "be", "hamlet"], your method should change the list's contents to ["be", "to", "not", "or", "be", "to", "hamlet"].
Computers and Technology
1 answer:
arsen [322]3 years ago
7 0

Answer:

  1. import java.util.ArrayList;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        ArrayList<String> strList =new ArrayList<String>();
  5.        strList.add("to");
  6.        strList.add("be");
  7.        strList.add("or");
  8.        strList.add("not");
  9.        strList.add("to");
  10.        strList.add("be");
  11.        strList.add("hamlet");
  12.        swapPairs(strList);
  13.        System.out.println(strList);
  14.    }
  15.    public static void swapPairs(ArrayList<String> list){
  16.        for(int i=0; i < list.size()-1; i+=2){
  17.            String temp = list.get(i);
  18.            list.set(i, list.get(i+1));
  19.            list.set(i+1, temp);
  20.        }
  21.    }
  22. }

Explanation:

Firstly, let's create a method swapPairs that take one ArrayList (Line 18). In the method, use a for-loop to traverse through each item in the ArrayList and swap the items between the current items at index-i and at index-i+1 (Line 19-22). The index-i is incremented by two in next loop and therefore the next swapping will proceed with third and fourth items and so forth.

In the main program, create a sample ArrayList (Line 5-12) and then test the method (Line 14) and print the output (Line 15). We shall get  [be, to, not, or, be, to, hamlet].

You might be interested in
If you reformat the hard drive on a computer, it erases all personal information from your computer and makes it safe to donate.
melamori03 [73]
The answer would be false
8 0
4 years ago
What is an example of using the internet of things (iot) to deliver innovative cloud-based solutions to customers?
Elina [12.6K]

Answer:

Wearable technology

Explanation:

An example of using the Internet of Things (IoT) to deliver innovative cloud-based solutions to customers is the wearable technology that provides customers with on-the-spot personalized experiences.

4 0
2 years ago
Help it’s an exam brainleist
andreyandreev [35.5K]

Explanation:

Automatic transaction machine

False

True

8 0
3 years ago
What common variation of the Server Message Block (SMB) sharing protocol is considered to be a dialect of SMB?
ser-zykov [4K]

Answer:

Common Internet File System

Explanation:

Given that the Server Message Block (SMB) has various types or variations. The most common variation of this Server Message Block sharing protocol that is considered to be a dialect of SMB is known as "Common Internet File System." This is known to serve as a form of a communication protocol for giving shared access to different outlets between nodes on a network.

Hence, in this case, the correct answer is "Common Internet File System"

8 0
3 years ago
How is gawain tempted​
jeyben [28]

Answer:

Sir Gawain and the Green Knight book cover

MENU

What are the temptations of Sir Gawain in "Sir Gawain and the Green Knight"?

print Print document PDF list Cite

Expert Answers info

HILLARD THIEL eNotes educator | CERTIFIED EDUCATOR

In addition to the obvious temptations in Berkilak's castle with his wife (all of which involve erotic temptation and the temptation to violate hospitality for personal pleasure), more significant spiritual temptations frame this story. First, Gawain displays an element of pride when he agrees to participate in the initial contest. While Arthur is more to blame and Gawain offers to take his place, it certainly is not prudent to participate in this contest with a character whose appearance suggests that he is not a normal, mortal man. The first part of this bargain therefore involves the temptation of pride.

r Gawain and the Green Knight by Pearl-Poet

Sir Gawain and the Green Knight book cover

MENU

What are the temptations of Sir Gawain in "Sir Gawain and the Green Knight"?

print Print document PDF list Cite

Expert Answers info

HILLARD THIEL eNotes educator | CERTIFIED EDUCATOR

In addition to the obvious temptations in Berkilak's castle with his wife (all of which involve erotic temptation and the temptation to violate hospitality for personal pleasure), more significant spiritual temptations frame this story. First, Gawain displays an element of pride when he agrees to participate in the initial contest. While Arthur is more to blame and Gawain offers to take his place, it certainly is not prudent to participate in this contest with a character whose appearance suggests that he is not a normal, mortal man. The first part of this bargain therefore involves the temptation of pride.

Later, the temptation that most condemns Gawain is the desire to continue living even if one will live a life compromised by deceit. While it is understandable that Gawain would hide the garter and flinch at the blow of an ax, the temptation to focus on his mortal rather than his spiritual life is the cause of his wearing the garter as a mark of shame.

Explanation:

6 0
3 years ago
Other questions:
  • Which of the following is an extension of the fill pattern Sunday,Tuesday?
    7·1 answer
  • Building relationships during your career exploration is called
    9·2 answers
  • Your colleagues are discussing the operation of a device in which packets are routed between VLANs on the device rather than hav
    7·1 answer
  • Ethan is a systems developer. He is working on a system where he will implement independent solutions for different processes. W
    14·1 answer
  • The TCP/IP ____ layer, sometimes called the Internet layer, is roughly equivalent to OSI's network layer.
    7·1 answer
  • The processor itself is not a resource, therefore the OS is not involved in deciding how much of the processor time is used for
    14·2 answers
  • We have the following class:
    6·1 answer
  • Briefly explain what are JavaScript librairies​
    12·1 answer
  • Class C Airspace inner ring begins at the __________ and extends vertically (by definition) to MSL charted values that generally
    5·1 answer
  • A technician is troubleshooting a Windows computer and needs to stop the explorer.exe process.Multiple attempts to open Task Man
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!