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]
3 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]3 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
3.1.5 Which network component connects a device to transmission media and allows the device to send and receive messages?
Rom4ik [11]

Answer:

Network Interface Card (NIC)

Explanation:

Also called Ethernet Card, the Network Interface Card (NIC) allows a computer or any device to make wired or wireless connections with other devices in a network. This connection made possible by the NIC allows the device to send and receive messages in the network.

An application of this is seen in Internet of Things(IoT) where devices communicate with one another. This is actually possible because all of the devices one way or the other have a network interface card.

8 0
3 years ago
Inattentional blindness occurs when individuals do not observe certain objects or events because they are focused on something e
PSYCHO15rus [73]
The answer is True have a good day
5 0
4 years ago
Read 2 more answers
Which part of the water cycle is most affected by a sunny day with few clouds?
nirvana33 [79]
Increase in evaporation
8 0
3 years ago
Read 2 more answers
The Letter keys are organized into three rows. Which of the following is not a letter key row?
defon

The answer is the Base Row. The home row is the middle row on the keyboard and where the fingers remain while at rest. The upper row and bottom row are the two rows above and below the home rows.

3 0
4 years ago
Read 2 more answers
Consumers must learn how to separate the truth from __ techniques
dmitriy555 [2]

Consumers must learn how to separate the truth from deceptive techniques.

Explanation:

Deceptive advertisements are hazardous for both consumer and advertiser. It is a misrepresentation of the nature of products or services promoted falsely by advertisers.

Professionals exploit consumers by following means:

  • false or incomplete information,
  • fraudulent activities
  • deceptive practices.

It may involve -

  • financial theft,
  • health risks,
  • scams, etc.  

Having proper knowledge about such practices and taking legal actions against fraudsters can help claim for the damages incurred.

3 0
4 years ago
Other questions:
  • An employee believes there is an imminent danger situation at her workplace. She contacts OSHA to report the safety hazard. Her
    8·1 answer
  • The operating system, and in particular the scheduler, is not an important component of a real-time system.
    14·1 answer
  • What government agency initially began the work with computers that would eventually lead to the development of the Internet?
    5·2 answers
  • A ______ workstation is a network terminal that supports a full-featured user interface, but limits the printing or copying of d
    5·1 answer
  • Answer for a, b, and c
    7·1 answer
  • A _____ miniature battery operated transmitter that can be propelled through a non-metallic pipe or purpose of locating
    6·1 answer
  • Kerry wants to save her file but give it a new name. Kerry should use the ____ command
    7·1 answer
  • Where is the quick access toolbar located?
    7·1 answer
  • You have a brand-new monitor and you want to make sure you are getting the most out of it. For this reason, you decide to alloca
    13·1 answer
  • quizlet ann is a security professional for a midsize business and typically handles log analysis and security monitoring tasks f
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!