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
Nimfa-mama [501]
3 years ago
14

Write two public static methods in the U6_L4_Activity_Two class. The first should have the signature swap(int[] arr, int i, int

j) and return type void. This method should swap the values at the indices i and j of the array arr (precondition: i and j are both valid indices for arr). The second method should have the signature allSwap(int[] arr) and return type void. The precondition for this method is that arr has an even length. The method should swap the values of all adjacent pairs of elements in the array, so that for example the array {3, 5, 2, 1, 8, 10} becomes {5, 3, 1, 2, 10, 8} after this method is called.
Computers and Technology
1 answer:
Tems11 [23]3 years ago
4 0

Answer:

public static void swap(int[] arr, int i, int j) {

   if(i >=0 && i <=arr.length-1 && j >=0 && j<=arr.length-1){

       int hold = arr[i];

       arr[i] = arr[j];

       arr[j] = hold;

   }

}

public static void allSwap(int[] arr) {

   if (arr.length % 2 == 0){

       for(int i=0; i<arr.length; i+=2){

           int hold = arr[i+1];

           arr[i+1] = arr[i];

           arr[i] = hold;

       }

   } else{

       System.out.println("array length is not even.");

   }

}

Explanation:

The two functions, swap and allSwap are defined methods in a class. The latter swaps the item values at the specified index in an array while the second accepts an array of even length and swap the adjacent values.

You might be interested in
Which of the following is the MOST important consideration when planning your budget?
Sladkaya [172]
C.budget for fixed expenses before flexiable expenses 

3 0
3 years ago
Read 2 more answers
Which of the following data types can hold a fractional (decimal) number?
zvonat [6]
A float data type can hold a decimal number.
6 0
2 years ago
Isabela wants to edit a presentation for her science class. She is in the main view of the PowerPoint application
Karolina [17]

Answer:Click the File tab, and click the Open option.

Explanation: correct on edge

8 0
4 years ago
What is the best way to limit a google search and get the most specific information possible?
Marrrta [24]
You go into settings on the google search and click advanced search. The rest you do on your own.
6 0
3 years ago
How would you define the rule of thirds?
mixer [17]

A pronciple of composition used fir centuries by artists and photographers or it is a method when used to frame a composition properly

8 0
3 years ago
Other questions:
  • A four-year old laptop will not boot and presents error messages on screen. You have verified with the laptop technical support
    11·1 answer
  • In a paragraph of no less than 125 words, describe how technology helps business professionals to be more efficient. Include exa
    12·2 answers
  • Terms that represents the achual speed used by device to transfer data​
    14·1 answer
  • The range of an area where users can access the Internet via high frequency radio signals transmitting an Internet signal from a
    8·2 answers
  • How has information technology made piracy possible
    14·1 answer
  • Which steps allow a user to change the column layout in the Handout Master?
    9·1 answer
  • Answer the queston...........​
    7·2 answers
  • the tool that is used on the form to display text that the user cannot change is a. textbox b. label c. button​
    9·1 answer
  • Identfy two duties of the governer stationed at mombasa under portugues rule?​
    8·1 answer
  • Ano ang ibig sabihin ng tanka<br>​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!