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
KIM [24]
3 years ago
5

We have written a method called sum with an int[] parameter nums. We want our sum method to compute the sum of nums, but our cod

e has a bug (or perhaps bugs?) in it.
Fix the bugs.

Computers and Technology
1 answer:
ira [324]3 years ago
8 0

Answer:

Following are the code to this question:

public class Main//defining a class-main  

{

public static int sum(int[] nums)//defining a method sum that accepts array  

{

int total = 0;//defining integer variable total

for(int num : nums) // use for-each loop

{  

total += num;//add array value in total variable

}

return total;//use return keyword to return the total value

}

public static void main(String []ar )//defining a main method  

{

int[] nums={1,2,3,4,5};//defining 1-D array nums

System.out.println(sum(nums));//use print function to call sum method  

}

}

Output:

15

Explanation:

In the class "Main", a static method, "sum" is defined, that accepts array in its parameter and inside the method, an integer variable "total" is define, that uses the for each loop to add array value in a total variable and use a return keyword to return its value.  

Inside the main method, an integer array nums are defined, that holds store some values and use the print function to call the sum method.

You might be interested in
How do i build a supercomputer.?
stira [4]
You will need one head node, at least a dozen identical compute nodes, an Ethernet switch, a power distribution unit, and a rack. Determine the electrical demand, cooling and space required. Also decide on what IP address you want for your private networks, what to name the nodes, what software packages you want installed, and what technology you want to provide the parallel computing capabilities
3 0
3 years ago
How are special characters added to a Word document? Check all that apply.
MrRissso [65]

It kinda depends on what you mean by special characters

7 0
2 years ago
Read 2 more answers
What is the top anime shows? <3
LenKa [72]

Answer:

This is personally based on my opinion.

My top 10 favorites

Toradora

Darling in the franxx

Lucky Star

My Melody

Death note

Attack on titans

One piece

The Promise neverland

Kaguya-sama: love is war

Black cover

4 0
2 years ago
Read 2 more answers
A presentation on the history of the Internet would mostlikely use the ____ pattern of organizationSpatialproblem-solutionchrono
m_a_m_a [10]

Answer:

topical

Explanation:

A presentation on the history of the Internet would mostlikely use the topical  pattern of organization.

3 0
3 years ago
An organization needs to maintain data files of its employees in the form of tables. They also need to access and update over th
QveST [7]
DBMS (DataBase Management System)
6 0
2 years ago
Read 2 more answers
Other questions:
  • The _____ icon looks like a clipboard with a page of paper attached. Cut Copy Paste Clipboard
    5·1 answer
  • Write a program that checks for car mileage. if the mileage is greater than 100000, display "clunker!". if not, display "buy it!
    7·1 answer
  • The producer thread will alternate between sleeping for a random period of time and inserting a random integer into the buffer.
    7·1 answer
  • What is a DreamScape?<br> Explain <br> and give example (if you want)
    10·1 answer
  • What are the synonyms for each word? :
    5·1 answer
  • One of your clients has opened a branch office in another state. Both the main office and the new branch office have fast, relia
    10·1 answer
  • How do you respond to an email?
    6·1 answer
  • Which of the following refers to a collection of colors, fonts, and effects that can be
    6·1 answer
  • Please help! first one to answer correctly gets brainliest and thanked
    7·1 answer
  • How will you maintain electrical tools and equipment?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!