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
1.
Umnica [9.8K]

Answer:

B

Explanation:

trust

7 0
3 years ago
Assign total_owls with the sum of num_owls_A and num_owls_B.
jonny [76]

Answer:

Explanation:

  • We declare the variable about the zoo with the owl's quantity, we could put any integer.
  • We make the sum operation zooA + zooB, with the variable total_owls.
  • we print the result about the two zoo.

num_owls_zooA= 3

num_owls_zooB = 4

total_owls = 0

total_owls = num_owls_zooA + num_owls_zooB

print('Number of owls:', total_owls)

3 0
3 years ago
We cannot use MS Word 2003 in laptop truebor false​
kvasek [131]

Answer:

False

Explanation:

we can use Microsoft Office Software on any laptop

7 0
3 years ago
Read 2 more answers
Is the method a network interface uses to access the medium and send data frames and the structure of these frames?
Alja [10]
Network technology <span>Is the method a network interface uses to access the medium and send data frames and the structure of these frames.</span><span />
3 0
3 years ago
whenever I try to make an account it says it can't sign me up at this time or something- can you help?-
Rus_ich [418]

Answer:

You can try emailing tech support and describing your issue. In order to get the best help as quickly as possible, try providing screenshots of what happens when you sign in or describe everything you see on the screen when the problem occurs, and quote error messages directly when possible.

5 0
3 years ago
Other questions:
  • You have decided to remove a recently installed feature which method can you use to remove this feature
    13·1 answer
  • Using the expected format, of putting key information where the reader can’t find it, is an example of?
    8·2 answers
  • Alex leads a team of eight members. Arrange his tasks in sequential order of phases of group dynamics. What are the stages in gr
    13·1 answer
  • The power we use at home has a frequency of 60 HZ. What is the time period of such a power?
    10·1 answer
  • What is Service Oriented architecture &amp; How is it different form Object Oriented Middleware?
    6·1 answer
  • Cellular digestion associated by what organelles?​
    5·2 answers
  • How many fixes are available for Adobe Photoshop CS4 (64 Bit)?
    9·1 answer
  • write a function named list_total that accepts a list as an argument (assume the list contains integers) and returns the cumulat
    11·1 answer
  • What's the best thing that's happened to you during quarantine?
    10·2 answers
  • How many binary digits are in 10^100.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!