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
Kelly is working on creating a rocket-focused game in Scratch and is ready to add some sound. What should Kelly do if she wants
Alja [10]

Answer:i think she should add a new sound from the soundtab and use the start sound block to attach her sound to the rocket.

Explanation:

8 0
3 years ago
Read 2 more answers
Write a program that prompts the user to input two numbers, a numerator and a divisor. Your program should then divide the numer
12345 [234]
What language? JavaScript? Python?
8 0
3 years ago
Read 2 more answers
Advertising andpublicity are used to:
WINSTONCH [101]

Answer:

d. All of the given options

Explanation:

Great question, it is always good to ask away and get rid of any doubts that you may be having.

<u>Advertising and Publicity</u> is used for many reasons.

Retail Companies use advertising and publicity to promote their products and in term increase sales of that product when it hits the shelves.

Meanwhile, other companies such as Law Firms use advertising and publicity create awareness for their law firm and communicate with customers over high profile case etc.

Therefore, the answer is all of the above.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

5 0
3 years ago
What is one reason employers appreciate employees that have high self-esteem?
AVprozaik [17]

Answer:

I think it is c

Explanation:

hope I helped

8 0
3 years ago
Read 2 more answers
Universal Containers uses an Auto-numbering system to uniquely identify each support request. They want customers to know this n
Nookie1986 [14]

Answer:

Following are the answers.

  • Auto-response Rules
  • Case Comment Notifications

Explanation:

They use the following system to determine that requirement for help in such a special manner. They need folks to identify the amount at the earliest opportunity. So, these Auto-response Rules and Case Comment Notifications are the functionalities that the System Admin implements to provide customers to easily obtain certain data are as follows.

8 0
3 years ago
Other questions:
  • Consider the folloeing website URL:http://www.briannasblog.com. What does the "http://" represent?
    11·1 answer
  • Which two software interfaces allow adjustment of the cpu voltage? (choose two.)?
    10·1 answer
  • "Technician A says that Ohm's law can be used to determine circuit current flow if total circuit resistance and total voltage ar
    14·1 answer
  • Everybody at a company is assigned a unique 9 digit ID. How many unique IDs exist?
    14·1 answer
  • Which of the following is the core of an operating system that maintains the computer’s clock, starts applications, and assigns
    5·1 answer
  • This morning when Paul turned on his computer at work, it would not boot. Instead, Paul reported that he heard a loud clicking n
    15·1 answer
  • How do you invite someone to a conversation on brainly
    14·1 answer
  • If you need some one to talk to you can talk to me
    13·2 answers
  • This is science I just couldn’t find it
    15·1 answer
  • 6. kinukuha nito ang kabuuang bilang ng mga numerical na datos sa mga piniling cells
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!