Write a method called switchThem that accepts two integer arrays as parameters and switches the contents of the arrays. Take into account that the arrays may be of different sizes.
What will be an ideal response?
```
public void switchThem(int[] first, int[] second)
{
if (first.length == second.length)
{
// copy contents of first into temp
int [] temp = new int[first.length];
for (int i = 0; I < first.length; i++)
temp[i] = first[i];
//copy contents of second into first
for (int i = 0; I < first.length; i++)
first[i] = second[i];
//copy contents of temp into second
for (int i = 0; I < first.length; i++)
second[i] = temp[i];
}
else
System.out.println("Arrays are of different sizes");
}
```
You might also like to view...
Answer the following questions true (T) or false (F)
1. All Collection classes are part of the java.util package. 2. Classes that implement the Set interface allows duplicate elements to occur.
Generate a Throughput Graph to view the data rate of the TCP connection. How does the throughput change after the flood of pings is started?
Why should a cybercrime law be specific?
a. To prevent defendants from finding loopholes b. So it will be internationally recognized c. So that multiple laws will not be necessary d. None of the above
In Windows applications, pressing the ____ and Tab keys simultaneously will move the focus backward.
A. Shift B. Ctrl C. Alt D. Ctrl+Shift