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
20 POINTS!!!
Rina8888 [55]

Answer:

the third one

hope this helps

5 0
3 years ago
You have a large company, and it is important to your business that your employees' work is backed up regularly. Which network w
valkas [14]
Client server network as it has a powerful server which provides all the networks required on the network. Files are usually backed up regularly.

3 0
3 years ago
Why is the engineering design process important to the customer?
Ket [755]

The engineering design process important to the customer layout system permits things: A shared technique on a way to discover and remedy problems. A framework to assess ideas, tell priorities and save you myopic paintings.

<h3>What is the maximum vital step withinside the engineering layout system?</h3>

The first step withinside the engineering layout system is to outline the trouble that you are solving. This step is the maximum vital, as a defective know-how of the trouble handy ends in layout failures. Engineers paintings to discover the foundation trouble via way of means of opposite engineering the signs and symptoms they perceive.

The engineering layout system, via way of means of definition, is a sequence of steps that engineers use to discover an option to a trouble. These steps include: defining the trouble, brainstorming solutions, designing and constructing a prototype of the solution, trying out the solution, and enhancing it.

Read more bout the engineering :

brainly.com/question/17169621

#SPJ1

8 0
2 years ago
A tripod head can move vertically or horizontally. What term describes these movements?
AnnyKZ [126]

The term for vertical movement of a tripod is Tilt. The term for horizontal movement is Pan.

Vertical movement of the camera angle involves pointing the camera up and down. This sort of movement is achieved so as to follow a subject or show the top and bottom of a still object. With Tilt, you can show how tall objects are. On the other hand, the tripod’s horizontal movement is used for a smooth effect. Like Tilting, it shows a subject or show the distance from left to right between two objects. Pan shots are great for panoramic views .

7 0
3 years ago
Read 2 more answers
Write a C program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many fil
amm1812

Answer:

see explaination

Explanation:

#include <iostream>

#include <fstream>

#include <sys/types.h>

#include <sys/stat.h>

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

using namespace std;

int main(int agrc,char*argv[])

{

struct stat sb;

if(agrc != 2){

cout << "invalind command line arguments "<< endl;

return 0;

}

if (stat(argv[1], &sb) == -1) {

perror("stat");

exit(EXIT_FAILURE);

}

if((sb.st_mode & 777) != 0) {

cout<<"file has permission and its invalid"<<endl;

}

//chmod(argv[1], S_IRWXU);

int status = chmod(argv[1], 0200);

if(status){

cout<<"permission sucessfull change"<<endl;

}

ofstream myfile;

myfile.open (argv[1], ios::out | ios::app);

myfile<<argv[2]<<endl;

status = chmod(argv[1], 0000);

if(status){

cout<<"permission sucessfull change

0000"<<endl;

}

myfile.close();

cout << "thank you" << endl;

return 0;

6 0
3 years ago
Other questions:
  • Decisions 1 and 3 are both ____________ decisions because ____________________.
    9·1 answer
  • A ____ attack is much more substantial than a DoS attack because of the use of multiple systems to simultaneously attack a singl
    13·1 answer
  • Holly would like to run an annual major disaster recovery test that is as thorough and realistic as possible. She also wants to
    5·1 answer
  • The set of instructions given to a computer is called _____________________.
    11·1 answer
  • What is the quickest option for adding internet images to a power point presentation
    7·1 answer
  • Participants in open _________ community projects get experience and make connections with other professionals that can be valua
    6·1 answer
  • Why might you receive a tax refund from the irs
    6·1 answer
  • Explain the main components of a computer system​
    12·1 answer
  • How do you increase the number of tries by one?
    10·1 answer
  • ________ is the general name for a security flaw in a program. Group of answer choices A security fault A virus Malware A vulner
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!