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
RTOS stands for ______ Time Operating System.
ch4aika [34]

Answer:

Real Time Operation System

Explanation:

6 0
3 years ago
Queries in Access can be used ______________
Alenkinab [10]
A query is an Access object used to view, analyze, or modify data. The query design determines the fields and records you see and the sort order.
6 0
3 years ago
List four tasks that humans perform frequently, but which may be difficult for a computerized agent to accomplish. Describe the
denis23 [38]

Answer:

im sorry for that

Explanation:

5 0
2 years ago
The data model shows the_______structrue of database.​
Kay [80]

The data model shows the <u>rows and columns</u> structrue of database.

6 0
3 years ago
Anybody know how to code?
Anni [7]

▪︎An onscreen camera for drawing virtual images is called "turtle" in python language.

\hookrightarrowThe codes we will be using in the following algorithm are :

▪︎Turtle.left

▪︎Turtle.right

▪︎Turtle.move #upward

\hookrightarrow An algorithm to help the python turtle reach the finish line :

  1. Turtle.left
  2. Turtle.left
  3. Turtle.left
  4. Turtle.move#upward
  5. Turtle.move#upward
  6. Turtle.move#upward
  7. Turtle.right
  8. Turtle.right
  9. Turtle.move#upward
  10. Turtle.left
3 0
3 years ago
Other questions:
  • The photo-sharing site Instagram owed a good deal of its success to filters. What are filters?
    11·2 answers
  • Which of the following statements will assign the contents of the Text property of a Textbox control named txtInput into the Tex
    10·1 answer
  • The conscious process of planning and controlling how you spend your time is called?
    15·1 answer
  • What type of hardward drive not require defragging??
    11·1 answer
  • How can a network design project benefit from the principles of itsm? How might itsm impede a network design project?
    11·1 answer
  • Eric has asked you to help him build a new gaming computer so that he can play the newest games available. He also wants the com
    6·1 answer
  • Wireshark is an example of what type of utility? A) Packet sniffer B) Port scanner C) Vulnerability scanner D) Content filter
    11·1 answer
  • Assume that sentence is a variable that has been associated with a string consisting of words separated by single space characte
    5·1 answer
  • Write a function findWithinThreshold that identifies the elements of a given array that are inside a threshold value. Takes the
    13·1 answer
  • What is the purpose of a report?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!