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
artcher [175]
2 years ago
12

Write a static method called split that takes an ArrayList of integer values as a parameter and that replaces each value in the

list with a pair of values, each half the original. If a number in the original list is odd, then the first number in the new pair should be one higher than the second so that the sum equals the original number. For example, if a variable called list stores this sequence of values:
Computers and Technology
1 answer:
lorasvet [3.4K]2 years ago
5 0

Answer:

The method is as follows:

public static void split(ArrayList<Integer> mylist) {

   System.out.print("Before Split: ");

   for (int elem = 0; elem < mylist.size(); elem++) { System.out.print(mylist.get(elem) + ", ");    }

   System.out.println();

   for (int elem = 0; elem < mylist.size(); elem+=2) {

       int val = mylist.get(elem);

       int right = val / 2;

       int left = right;

       if (val % 2 != 0) {            left++;        }

       mylist.add(elem, left);

       mylist.set(elem + 1, right);    }        

   System.out.print("After Split: ");

   for (int elem = 0; elem < mylist.size(); elem++) { System.out.print(mylist.get(elem) + ", ");    }

}

Explanation:

This declares the method

public static void split(ArrayList<Integer> mylist) {

This prints the arraylist before split

<em>    System.out.print("Before Split: "); </em>

<em>    for (int elem = 0; elem < mylist.size(); elem++) { System.out.print(mylist.get(elem) + ", ");    } </em>

<em>    System.out.println(); </em>

This iterates through the list

   for (int elem = 0; elem < mylist.size(); elem+=2) {

This gets the current list element

       int val = mylist.get(elem);

This gets the right and left element

<em>        int right = val / 2; </em>

<em>        int left = right; </em>

If the list element is odd, this increases the list element by 1

       if (val % 2 != 0) {            left++;        }

This adds the two numbers to the list

       mylist.add(elem, left);

       mylist.set(elem + 1, right);    }      

<em>This prints the arraylist after split</em><em> </em>

<em>    System.out.print("After Split: "); </em>

<em>    for (int elem = 0; elem < mylist.size(); elem++) { System.out.print(mylist.get(elem) + ", ");    } </em>

<em>}</em>

You might be interested in
Blind spots are those areas not reflected in your:
bulgar [2K]
The answer is C because your sideview and rearview mirrors are there specifically to check behind you, while the vanity mirror is not supposed to be used for the same purpose.
8 0
3 years ago
Read 2 more answers
Which of the following is NOT a long-term storage device?
neonofarm [45]

The storage device which is not a long-term storage device is: D. RAM.

<h3>Types of computer memory.</h3>

In Computer technology, there are two (2) main types of memory or storage location for software program (application) that are being used on a computer and these include the following;

  1. Read only memory (ROM)
  2. Random access memory (RAM)

<h3>What is RAM?</h3>

RAM is an abbreviation for random access memory and it can be defined as a volatile and temporary storage (memory) location that is used for currently opened software program (application) and computer data.

In conclusion, we can reasonably and logically deduce that the storage device which is not a long-term storage device is random access memory (RAM).

Read more on RAM here: brainly.com/question/13748829

#SPJ1

3 0
1 year ago
Consider a hypothetical microprocessor generating 16-bit addresses with 16-bit data accesses (i.e. each access retrieves 16 bits
Vlad [161]
A. number of addresses is 65536
b. memory capacity is 128 kbytes or 131072 bytes
c. The last memory address is FFFF which is 65535

8 0
3 years ago
ASAP!!!!****** Need help!!!!
m_a_m_a [10]
I think it's right. 
<span>Text, numbers, graphics, or sound represented by discrete digits, such as 1s and 0s.</span>
6 0
3 years ago
Two types of business communications enhanced by desktop publishing are
Likurg_2 [28]
The correct option is D.
The two types of business communication that are enhanced by desktop publishing are internal and external communication. Internal communication refers to the information and ideas that are exchange within the organisation while external communication refers to information and ideas that are exchange between the organisation and the outside world.<span />
4 0
3 years ago
Read 2 more answers
Other questions:
  • Which PowerPoint options can users customize?
    9·1 answer
  • How are texting and instant messaging alike?
    6·2 answers
  • Which of the following statements describes a good reason to use lossless audio compression?
    6·1 answer
  • Why does my hp computer keep freezing when i move it?
    10·1 answer
  • Select the correct answer.
    10·1 answer
  • Who is on ig and would like to be friends?​
    8·2 answers
  • Which of the following variable names follows the rules for naming variables?
    13·1 answer
  • Quick!! Im taking a timed test so pls hurry!! Ill even mark as brainliets!!
    5·2 answers
  • What kind of skill is persuasion?
    7·1 answer
  • Como interactua el hardware de la computadora con el ser humano
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!