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
Ber [7]
3 years ago
6

Write a method named collapse that accepts an array of integers as a parameter and returns a new array where each pair of intege

rs from the original array has been replaced by the sum of that pair. For example, if an array called a stores {7, 2, 8, 9, 4, 13, 7, 1, 9, 10}, then the call of collapse(a) should return a new array containing {9, 17, 17, 8, 19}. The first pair from the original list is collapsed into 9 (7 2), the second pair is collapsed into 17 (8 9), and so on.
Computers and Technology
1 answer:
maxonik [38]3 years ago
8 0

Answer:

The method in Java is as follows:

public static void collapse(int [] myarr) {  

       int [] arr = new int[myarr.length/2];

       int k = 0;

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

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

           k++;

       }

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

           System.out.print(arr[i]+" ");

       }

   }  

Explanation:

This defines the collapse method

public static void collapse(int [] myarr) {  

This declares a new array

       int [] arr = new int[myarr.length/2];

This declares and initializes k to 0

       int k = 0;

This iterates through the array passed as argument

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

This calculates the elements of the new array

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

           k++;

       }

The following iteration returns and prints the elements of the new array

<em>        for (int i = 0;i<myarr.length/2;i++){</em>

<em>            System.out.print(arr[i]+" ");</em>

<em>        } </em>

   

<em>See attachment for complete program which includes the main</em>

Download txt
You might be interested in
Which of the following are incident priorities?
xenn [34]

Answer:

what are the options?

reply in comment so i can help:)

5 0
3 years ago
In the computer science industry, the process of finding and removing errors from computer hardware or software is known as
Katyanochek1 [597]
Debugging i think it is
3 0
3 years ago
Cultural competence​ involves
IrinaK [193]

Answer:

Cultural competence involves more than having sensitivity or awareness of cultures. It necessitates an active process of learning and developing skills to engage effectively in cross-cultural situations and re-evaluating these skills over time.

Explanation:

3 0
3 years ago
What is one reason the number of DUIs has dropped?
nikdorinn [45]

Answer:

Ride Sharing Services

Explanation:

Choosing to take Uber or have a designated driver instead of driving under the influence than have fewer students because fewer people are getting caught diving under the influence.

8 0
3 years ago
How to do a row of circles on python , with the commands , picture is with it .
kotykmax [81]

Answer:

o.o

Explanation:

5 0
3 years ago
Other questions:
  • You have implemented nap with dhcp enforcement, so you need to ensure you have an updated anti-virus software package, an update
    7·1 answer
  • you want to search in your contacts in your email program. You enter the person's first name and last name in the search box. Yo
    8·1 answer
  • Which of the following is a professional organization in the field of IT? Society for the Prevention of Cruelty to Animals (SPCA
    6·2 answers
  • What is indirect recursion?
    14·1 answer
  • A printer is connected locally on Computer1 and is shared on the network. Computer2 installs the shared printer and connects to
    10·1 answer
  • Usually, in organizations, the policy and mechanism are established by the:
    14·2 answers
  • What do we do if IOC is called on the intercom ??
    14·1 answer
  • Tascake Gets Free Brainliest Because he didnt get it<br><br> Tascake Heres Brainliest
    6·2 answers
  • Abdul wants to create a header for a webpage and enters this line: Welcome to Abdul’s webpage! , but the title is smaller than w
    12·1 answer
  • Consider the following method, which is intended to count the number of times the letter "A" appears in the string str.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!