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
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input
natita [175]

Answer:

The program in Python is as follows:

firstName = []

lastName = []

while True:

   fName = input("First Name: ")

   lName = input("Last Name: (Enter to quit): ")

   if not lName:

       break

   firstName.append(fName)

   lastName.append(lName)

for i in range(len(firstName)):

   print(firstName[i] . lower()+"."+lastName[i] . lower()+" mycollege . edu")

Explanation:

See attachment for complete source file where comments are used as explanation

Download txt
8 0
3 years ago
The hardware to keep the output data when finished is a
Bess [88]
I believe the answer is modem
4 0
3 years ago
In modern computer memory, each location is normally composed of one byte.
Paraphin [41]
An actual parameter in a method call, or one of the values combined by an operator
4 0
3 years ago
Tonya is working with a team of subject matter experts to diagnose a problem with her system. The experts determine that the pro
Licemer1 [7]

Answer:

The answer of the following question is Encryption.

Explanation:

Encryption is the second layer of the OSI Layer. It helps reduce the maintenance charges and offload complexity.

Encryption has presents in layer 3 and layer 4 which is IPSec in layer 3 and SSL, TSL in layer 4. of OSI Model.

<u>Note</u>- Only the Encryption can protect the data itself

5 0
3 years ago
Most presentations use text: A. To maximize area and style. B. At a minimum. C. To draw attention to content. D. Without restrai
klemol [59]

The answer is most likely A.


Hope this Helped!


;D

4 0
3 years ago
Read 2 more answers
Other questions:
  • Given main(), define the Team class (in file Team.java). For class method getWinPercentage(), the formula is:teamWins / (teamWin
    15·1 answer
  • What would happen to a eukaryotic cell if all its mitochondriawere destroyed
    7·1 answer
  • A method that receives a two-dimensional array uses two ____ pairs following the data type in the parameter list of the method h
    11·1 answer
  • Google Glass, glasses that allow you to take pictures and search online by speaking commands, are introduced at a technology tra
    8·1 answer
  • What is the output of the following program?
    11·1 answer
  • What type of version of visual studio is the visual studio express
    8·1 answer
  • The best way to ensure the accuracy and safety of your accounts is to:
    10·1 answer
  • Whats the formatting of a letter to the editor?​
    12·1 answer
  • How does the issue of cybersecurity relate to the internet of things?.
    5·1 answer
  • You are the security analyst for your organization and have discovered evidence that someone is attempting to brute-force the ro
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!