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
PLZ HELP!! How does HTML help solve the problem of telling a computer what a web page looks like, not just the content that is o
Anastasy [175]

Answer:

HTML is a code language. computers understand things in different ways because of the different languages that people use in code..(java, C++, HTML, etc.) Thus, if you understand the coding of HTML, that means you should be able to add things to your website anytime you want. you can even have links to other sites that are designed the same way, giving the illusion of rooms in a website I guess... If a website has links, you can have more information without storing it on the main paige and cluttering everything up together...

I hope this answered your question.

8 0
3 years ago
Why wont it let me get another free trial on adobe photoshop?
k0ka [10]
A free trial is a one-time thing. Try using another email address or something. 
3 0
3 years ago
HELP ME PLEASE
MAXImum [283]

Explanation:

Threats

Computer Security Threats are possible dangers that can affect the smooth functioning of your PC. These may be a small piece of adware or a harmful Trojan malware. In the present age, computer security threats are constantly increasing as the world is going digital. computer security threats

Types of Computer Security Threats

There are several types of computer security threats such as Trojans, Virus, Adware, Malware, Rootkit, hackers and much more. Check some of the most harmful types of computer Security Threats.

COMPUTER VIRUS

A Computer Virus is a malicious program, which replicates itself and infects the files and programs of your PC and can make them non-functional.

COMPUTER WORMS

A self-replicating computer program that spreads malicious codes, computer worms make use of the network to send copies of the original codes to other PCS. It can also go to the extent of sending transferring documents utilizing the email of the user.

SCAREWARE

Scareware is a malware that tricks victims to buy software by displaying fake virus alerts. A scareware infected PC may get pop-ups of fake malware threats and to get rid of those, users are prompted to purchase a fake anti-malware software.

KEYLOGGER

Also known as a keystroke logger, Keyloggers can track the real-time activity of a user on his computer. Keylogger runs in the background and records all keystrokes made by a user and passes the information to the hacker with the motive to steal password and banking details.

ROOTKIT

A rootkit is considered extremely dangerous as they appear to be legitimate files and deceives the computer user. Rootkit masks viruses and worms and makes them appear as necessary files. These are very difficult to remove and only an antivirus with the anti-rootkit feature can remove a rootkit.

Tips for Best Computer Security

For best computer security, you must follow certain guidelines, which are also called computer best practices. 1. Use the best antivirus software, which not only provides protection to your PC but also internet protection and guards against cyber threats. 2. Do not download untrusted email attachments and these may carry harmful malware. 3. Never download software from unreliable sites as they may come with a virus that may infect your system as soon as you install the software.

4 0
2 years ago
Most editing commands in Word, such as cut, copy, and paste, can be found on which tab?
Anettt [7]
All these commands can be found on the home tab. Keyboard shortcuts (Ctrl-X, Ctrl-C, Ctrl-V) are also editing shortcuts.

:)
7 0
3 years ago
Read 2 more answers
What is ‘Software Testing’?
SCORPION-xisa [38]

Answer: Software testing can be referred as an as activity that one execute in order to verify whether the results match expected results and also to make sure that software system is without any defect. It also tends to involve execution of few software component in order to evaluate several properties.  This majorly helps to identify gaps, error or requirements that are missing in respect to actual requirements.

5 0
3 years ago
Other questions:
  • Technician A says copper has a low resistance. Technician B says the length of wire doesn't affect resistance. Who is correct?
    11·1 answer
  • Describe how data center storage applications drive the development of SAN technology.
    8·1 answer
  • What can be said about the equipment used by photographers during the Civil War?
    13·2 answers
  • What's a good drawing tablet?
    12·2 answers
  • Ask me anything about grades kindergarten to fifth grade!
    12·1 answer
  • What is processing requirement in computer?
    11·1 answer
  • THIS IS FOR MY FINAL PLEASE HELP
    6·1 answer
  • Comments should Your answer: rephrase the code it explains in English be insightful and explain what the instruction's intention
    15·1 answer
  • What is a digital dashboard, and why are they becoming an increasingly popular tool?
    15·2 answers
  • Which statement best describes network security?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!