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
What is a boolean in Java
gayaneshka [121]
C; a true or false value
7 0
3 years ago
Each instruction that the CPU receives contains two parts -
Artist 52 [7]
E :) ahksksowokskxksos
4 0
3 years ago
Keli is unable to find a shape that meets her needs. Which feature in Power Point should she use to create shapes that are compl
VladimirAG [237]

Answer:

I just use the search bar in the app and type in shapes. Then you right click on the shape and click on edit points to shape it into whatever shape you want.

Explanation:

I went into the PowerPoint and did it myself.

7 0
3 years ago
Write a paragraph about ICT in personal life?
melisa1 [442]

Answer:

Information and communications technology (ICT) is an extensional term for information technology (IT) that stresses the role of unified communications[1] and the integration of telecommunications (telephone lines and wireless signals) and computers, as well as necessary enterprise software, middleware, storage and audiovisual systems, that enable users to access, store, transmit, and manipulate information.

6 0
3 years ago
What is the correct process for selecting an entire row in a spreadsheet?
Valentin [98]
A. Click on any cell in the row
7 0
3 years ago
Other questions:
  • In an is framework, ________ is the bridge between the computer side on the left and the human side on the right
    12·1 answer
  • Which protocol is used by the client for microsoft networks and file and printer sharing for microsoft networks to communicate w
    10·1 answer
  • If you implement a Wireless LAN (WLAN) to support connectivity for laptops in the Workstation Domain, which domain does WLAN fal
    5·1 answer
  • Which of the following is generally nota desire today's workers? A. computer ability B willingness to learn C. teamwork skills D
    8·1 answer
  • How many inches do a tire have to be to sometimes be refer as bald of balding tries
    14·1 answer
  • What percentage of business are using social media today
    14·1 answer
  • One of the best ways to shoot a picture is to frame the subject in the middle of the screen or viewer. T or F
    14·2 answers
  • A digital forensic analyst examines the original digital source (e.g. computer, flash drive, backup tape) suspected of being inv
    5·1 answer
  • How do people decide their ethical behavior
    13·2 answers
  • One of 34 possible _________________ can be assigned to each axis of classification in the seven-character code.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!