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
3. How are you able to create photographs differently than 100 years ago?
Agata [3.3K]

Answer:

it willbe black and white

Explanation:

3 0
2 years ago
Read 2 more answers
Which ipsec component is software that handles the tasks of encrypting, authenticating, decrypting, and checking packets?
ad-work [718]
The ipsec component software that handles the tasks of encrypting, authenticating, decrypting, and checking packets is called IKE.  It is short for Internet Key Exchange.  It is <span>a network security Protocol aimed to allow two devices to actively exchange Encryption Keys and negotiate Security Associations </span>
8 0
2 years ago
Use input() function to take 4 user inputs as variables and choose at least 2 ways to print out the following statements. You ca
taurus [48]

Answer:

statements = tuple(input("Enter four statements separated by comma: ").split(","))

st1, st2, st3, st4 = statements

#print with:

print(f"{st1}, {st2}, {st3}, {st4}")

# or:

print("{}, {}, {}, {}".format(st1, st2, st3, st4))

Explanation:

The input function in python is used to prompt for user input. It returns a string. The code above splits the string of the input function and converts it to a tuple, which is unpacked in four variables st1, st2, st3, and st4.

The variables can be printed out as strings directly or by using the "f" keyword or the format function.

6 0
2 years ago
How can the storage model assist in the design of storage networks?
kupik [55]

Answer:

 The storage model basically used for protecting the confidential data and information. It is important for the security purpose during the accessing of the data to make it more easy.

There are basically different types of storage model that used to assign in the designing of the storage network are:

  • Hard drive storage is basically used for the data storage in the local hard drive which is used by the sever.
  • Online storage is one of the most secure and most secure choices, the information is put away on various framework which help in protected and secure exchange of the information regardless of whether one of the framework is fizzled. it is also known as cloud storage device.
  • The network storage is also used fr storing the data in the server.

7 0
3 years ago
Describe the difference between gui and cli​
konstantin123 [22]

Answer:

The main difference between GUI and CLI is that the Graphical User Interface (GUI) allows the user to interact with the system using graphical elements such as windows, icons, menus while the Command Line Interface (CLI) allows the user to interact with the system using commands.

Explanation:

3 0
3 years ago
Other questions:
  • Explain Organizational approach to System Analysis and Design
    11·1 answer
  • Look at the four schematic symbols shown in the figure above. Each of the symbols is labeled with a number. Which of the followi
    5·2 answers
  • Type the correct answer in the box spell all words correctly
    8·1 answer
  • A quick boot allows you to do what?
    7·2 answers
  • A technician is talking to end users about the specifications for an upgraded application server. The users of the application r
    11·1 answer
  • Site won't let me log in and is glitching? Is rainly down?
    15·2 answers
  • Hardware refers to programs and protocols used on a computer system.<br><br> True<br> False
    8·2 answers
  • Using filtering as a strategy to deal with information overload requires Group of answer choices reviewing all unsolicited infor
    14·1 answer
  • Write a program to find the principle amount​
    10·1 answer
  • How would you explain how a password generator program works
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!