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
Knowing what you know now about frequency analysis, would you feel comfortable sending your password over the Internet using a s
Vikki [24]
According to my opinion, NO, I'd not feel comfortable.

Substitution ciphers in the world of encryption can be cracked very easily. By looking for patterns like one letter words, double letter patterns, and knowing rules such as all words must contain at least an a, e, i, o, u or y, you are probably able to decipher this with so much ease. While this information and the frequency of letters used in the encrypted message might be helpful, it might not be a perfect process.


8 0
3 years ago
Read 2 more answers
In Qbasic how I type the diference between two numbers?
zavuch27 [327]

Answer:

REM PROGRAM TO DISPLAY SUM OF TWO NUMBERS

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

S = A + B

PRINT “SUM OF TWO NUMBERS”; S

END

USING SUB PROCEDURE

DECLARE SUB SUM (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

CALL SUM(A, B)

END

SUB SUM (A, B)

S = A + B

PRINT “SUM OF TWO NUMBERS”; S

END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUM (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

S = SUM(A, B)

PRINT “SUM OF TWO NUMBERS”; S

END

FUNCTION SUM (A, B)

SU = A + B

SUM = SU

END FUNCTION

2. Enter any two numbers and display its difference.

REM PROGRAM TO DISPLAY DIFFERENCE OF TWO NUMBERS

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

D = A - B

PRINT “DIFFERENCE OF TWO NUMBERS”; D

END

USING SUB PROCEDURE

DECLARE SUB DIFF (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

CALL DIFF(A, B)

END

SUB DIFF (A, B)

D = A - B

PRINT “DIFFERENCE OF TWO NUMBERS”; D

END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION DIFF (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

DI = DIFF(A, B)

PRINT “DIFFERENCE OF TWO NUMBERS”; DI

END

FUNCTION DIFF (A, B)

D = A - B

DIFF = D

END FUNCTION

3. Enter any two numbers and display its product.

REM PROGRAM TO DISPLAY PRODUCT OF TWO NUMBERS

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

P = A * B

PRINT “PRODUCT OF TWO NUMBERS”; P

END

USING SUB PROCEDURE

DECLARE SUB PROD (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

CALL PROD(A, B)

END

SUB PROD (A, B)

P = A * B

PRINT “PRODUCT OF TWO NUMBERS”; P

END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PROD (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

PR = PROD(A, B)

PRINT “PRODUCT OF TWO NUMBERS”; PR

END

FUNCTION PROD (A, B)

P = A * B

PROD = P

END FUNCTION

4. Enter any two numbers and display its average.

REM PROGRAM TO DISPLAY AVERAGE OF TWO NUMBERS

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

AV = (A + B) / 2

PRINT “AVERAGE OF TWO NUMBERS”; AV

END

USING SUB PROCEDURE

DECLARE SUB AVERAGE (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

CALL AVERAGE(A, B)

END

SUB AVERAGE (A, B)

AV = (A + B) / 2

PRINT “AVERAGE OF TWO NUMBERS”; AV

END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION AVERAGE (A, B)

CLS

INPUT “ENTER FIRST NUMBER”; A

INPUT “ENTER SECOND NUMBER”; B

AVGR = AVERAGE(A, B)

PRINT “AVERAGE OF TWO NUMBERS”; AVGR

END

FUNCTION AVERAGE (A, B)

AV = (A + B) / 2

AVERAGE = AV

END FUNCTION

Explanation:

Pls mark brainliest

8 0
2 years ago
Read 2 more answers
What's the keyboard command that will allow you to "copy" text?
lana66690 [7]

For mac/apple operating systems; command c to copy command v to paste

For windows operating systems; control c to copy control v to paste

4 0
3 years ago
Read 2 more answers
Which of the following is true? You are a project manager for Laredo Pioneer's Traveling Rodeo Show. You're heading up a project
nika2105 [10]

Answer: C. You are a project manager for Laredo Pioneer's Traveling Rodeo Show. You're heading up a project to promote a new line of souvenirs to be sold at the shows. You're ready to document the processes you'll use to perform the project as well as define how the project will be executed and controlled and how changes will be monitored and controlled. You are working on the project management plan.

Explanation:

4 0
3 years ago
A cybercrime: Select one: a. Is the act of defaulting on a properly signed agreement entered into upon the internet. b. Can be c
aalyn [17]

The answer is B because cyber crime is when a computer is used to commit criminal activities.

3 0
4 years ago
Other questions:
  • Which is an example of withholding you might see on your pay stub
    14·2 answers
  • Given the list my_list containing integers, create a list consisting of all the even elements of my_list. Associate the new list
    12·1 answer
  • The What is the pathname that starts from the working directory. directory?
    7·1 answer
  • What is UTF-8 and why was it created?
    8·1 answer
  • Write a program that will manipulate Rectangle objects for which you will create a Rectangle class.
    5·1 answer
  • A clock is reading 10:27:54.0 (hr:min:sec) when it is discovered to be 4 seconds fast. Explain why it is undesirable to set it b
    9·1 answer
  • Anyone know how to do point hack​
    9·2 answers
  • Sypherpk is good go sub 2 him
    6·2 answers
  • By what other name can the folders in Windows 7 be called?
    5·1 answer
  • Why should you avoid the use of sarcasm, clichés, and idioms in business<br> letters
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!