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
Nikitich [7]
3 years ago
6

Create a static method that: - is called appendPosSum - returns an ArrayList - takes one parameter: an ArrayList of Integers Thi

s method should: - Create a new ArrayList of Integers - Add only the positive Integers to the new ArrayList - Sum the positive Integers in the new ArrayList and add the Sum as the last element For example, if the incoming ArrayList contains the Integers (4,-6,3,-8,0,4,3), the ArrayList that gets returned should be (4,3,4,3,14), with 14 being the sum of (4,3,4,3). The original ArrayList should remain unchanged.
Computers and Technology
1 answer:
Flura [38]3 years ago
3 0

Answer:

The method in Java is as follows:

public static ArrayList<Integer> appendPosSum(ArrayList<Integer> nums) {

   int sum = 0;

   ArrayList<Integer> newArr = new ArrayList<>();

   for(int num : nums) {

       if(num>0){

           sum+=num;

           newArr.add(num);        }    }

   newArr.add(sum);

   return newArr;

 }

Explanation:

This defines the method; it receives an integer arraylist as its parameter; nums

public static ArrayList<Integer> appendPosSum(ArrayList<Integer> nums) {

This initializes sum to 0

   int sum = 0;

This declares a new integer arraylist; newArr

   ArrayList<Integer> newArr = new ArrayList<>();

This iterates through nums

   for(int num : nums) {

If current element is greater than 0

       if(num>0){

This sum is taken

           sum+=num;

And the element is added to newArr

           newArr.add(num);        }    }

At the end of the iteration; this adds the calculated sum to newArr  

newArr.add(sum);

This returns newArr

   return newArr;

 }

You might be interested in
In which drawer can you set certain lights to light up on your micro:bit?
zheka24 [161]

Answer:

In which drawer can yu set certain lights t light up n yur micr:bit?

Explanation:

4 0
3 years ago
Read 2 more answers
Find the median and mean of the data set below: 29 17 40 12 29
quester [9]

answer:

median: 29

arrange the data in ascending order, and the median is the value in the middle. If there are an even number of values, the median would be the product of the two middle numbers. (12, 17, 29, 29, 40)

mean: 25.4

the mean of a set of numbers is the sum divided by the number of terms.

12 + 17 + 29 + 29 + 40 = 127 / 5 = 25.4

hope this helped!

6 0
2 years ago
Where is the viscosity of engine oil found
Rashid [163]
In the crankcase
I hope this helps
8 0
3 years ago
Midday is a good time to take a portrait outside.<br> true or false?
Over [174]

Answer:

B: False

Explanation:

edg2020

4 0
2 years ago
A tornado destroyed many
m_a_m_a [10]

Answer:

D is your answer because I'm an expert

5 0
3 years ago
Read 2 more answers
Other questions:
  • Among the web programming languages, css is used to define _____ of the web page
    5·1 answer
  • Anna always has a hard time finding files on her computer because she does not know where she saved them. This also affects her
    12·2 answers
  • A style manual can be described as
    11·2 answers
  • In order to get a comprehensive evaluation of the computer programmers he managed, Justin organized a(n) __________, where he as
    11·1 answer
  • How do you get banned? By getting reported? Or do admins watch whats posted?
    9·1 answer
  • Devices which are used to receive data from central processing unit are classified as
    11·1 answer
  • Explain the computer according to size​
    10·1 answer
  • Which item is used for formatting in responsive web design?
    14·2 answers
  • Which term describes a visual object such as a picture a table or text box
    15·2 answers
  • A monopoly is a market that has few competing businesses. many sellers of the same item. many sellers of a variety of products.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!