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
Joe has just started the Security Module. He wants to get through it as quickly as possible and take the Quiz. As he clicks thro
Scorpion4ik [409]

Answer:

Joe should read the explanatory text and complete the learning activities.

Explanation:

Given

See attachment for options

Required

Best strategy to get through the module

First off, rushing through the activities and taking guess for each question (as suggested by (a)) will not help him;

He may complete the activities but sure, he won't learn from the module.

Also, reading through the units without completing the activities is not an appropriate method because Joe will not be able to test his knowledge at the end of the module.

The best strategy to employ is to read through the units and complete the activities, afterwards (option (b)).

4 0
3 years ago
Give the names of two different places you might find a number represented in hexadecimal
Paladinen [302]

Answer:

Monday or Tuesday or Wednesday I am going back to work

Explanation:

8 0
2 years ago
Web browsers are used to browse the World Wide Web. <br> True or false
irakobra [83]
It's true. When you use an adress link you can see that it begin with www and that means world wide web
8 0
3 years ago
Read 2 more answers
Compare Ethernet frames to other frames.
harina [27]
Most frames use crux and I can only do a couple
4 0
3 years ago
Please help!! thank you so much!! &lt;3
sasho [114]

Answer: <em>The kinetic energy of the 20 gram ball is half the kinetic energy of the 10 gram ball.</em>

<em />

Explanation: :)

7 0
3 years ago
Read 2 more answers
Other questions:
  • Assign to avg_owls the average owls per zoo. Print avg_owls as an integer. Sample output for inputs: 1 2 4 3
    7·1 answer
  • Janet is testing the effectiveness of four different plant foods. She plants four identical seeds in four identical pots, supply
    6·2 answers
  • Josh's boss asked him to write a letter to their customers explaining some upcoming price increases. But Josh was in a hurry to
    8·2 answers
  • #11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu
    6·1 answer
  • Consider the following C++ program in which the statements are in the incorrect order. Rearrange the statements so that itprompt
    6·1 answer
  • You load an image file into a numpy array and look at its shape, which is (433, 650). What does this indicate?
    13·1 answer
  • Cloud suites are stored on your hard drive and are available anywhere you can access the Internet
    15·1 answer
  • Which of the following is an example of joint problem solving?
    12·1 answer
  • Describe risk avoidance. Name three common methods of risk avoidance.
    5·1 answer
  • William brought some data into his Tableau Book, but the data had some null values and incorrect column headers. What did Willia
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!