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
Maurinko [17]
3 years ago
12

Write a method with the header public static void swapAdjacent(int[] values) that takes a reference to an array of integers valu

es and swaps adjacent pairs of elements: values[0] with values[1], values[2] with values[3], etc. For example, if you add the following test code to your main method: int[] a1 = {0, 2, 4, 6, 8, 10}; swapAdjacent(a1); System.out.println(Arrays.toString(a1));
Computers and Technology
1 answer:
andreev551 [17]3 years ago
3 0

Answer:

public static void swapPairs(int[] a){

   int len=a.length;

       if(len%2 ==0){

           for(int i=0; i<len; i=i+2){

               a[i]=a[i+1];

               a[i+1]=a[i];

               int[] b={a[i]+a[i+1]};

           }    

       }

       if(len%2 !=0){

           for(int j=0; j<len; j=j+2){

               a[j]=a[j+1];

               a[j+1]=a[j];

               a[len-1]=a[len-1];

               int[] b={a[j]+a[j+1]+a[len-1]};

           }

       }    

}

public static void printArray(int[] a){

   System.out.println(a);

}

You might be interested in
A USB flash drive uses solid
steposvetlana [31]
State drive. SSD=Solid State Drive
8 0
3 years ago
Which elements of a myth appear in this story from early babylon
g100num [7]
-a setting that may be fake
- Supernatural being/character
- Conflict/ the plot of the story
7 0
3 years ago
If the cpu is fast but the bus speed is slow, that condition is called?
yanalaym [24]
A slow processors but the need more bytes
5 0
2 years ago
Programmers refer to a sequence of characters as a ____.
jekas [21]
In programming they know it as a String which is  a sequence of characters that are composed of literal constants or some kind of variables. A sting is any finite sequence of characters. every single string has its own lenght and this is one of the most important characteristics of them. Strings are essential to communicate information from the program to the user. 
5 0
3 years ago
Please answer the following essay question:
MArishka [77]
Advertising is a paid promotion that uses strategic planning to target a certain audience. The seven functions of marketing is promotion, selling, product management, marketing information management, pricing, financing, and distribution. Usually you see common advertising such as digital ads, billboards, newspapers, flyers, and more. Advertising can spread awareness, popularize a brand, increase customer demand, and company profits. Advertising is necessary for most- if not all- companies including media outlets, the television industry, search engine companies, and social media websites.
8 0
3 years ago
Other questions:
  • Write a character literal representing the (upper case) letter<br> a.
    13·1 answer
  • When are the malls going to open
    5·2 answers
  • Which type of natural hazard is sometimes caused by human activity?
    6·1 answer
  • Let's say that you want to create a new Integer array with a size of 56. Pick the array that would accomplish this:
    14·1 answer
  • You want to use a computer to make a painting of your backyard to go along with a story you wrote. Which software would be appro
    8·1 answer
  • 0 -10°
    12·1 answer
  • Cách soạn thảo văn bản trên word
    7·1 answer
  • Which of the following makes Super Mario Run unique?
    6·1 answer
  • What are the common operations performed on character strings?
    8·1 answer
  • failed logins or instances of denial of access to restricted files may be indicators of compromise. suggest where records of suc
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!