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
Why must programs written in a high-level language be translated into machine language?
eimsori [14]
The only thing that a computer actually understands is machine language. English-like constructs are gibberish to a computer, so they need to be translated by a compiler to machine language to run natively.
4 0
3 years ago
Which two protocols manage neighbor discovery processes on ipv4 networks?.
serious [3.7K]

Answer:

Which two protocols manage neighbor discovery processes on IPv4 networks? TCP and UDP BGP and OSPF ICMP and ARP IPv4 and IPv6

Key Links. Pricing.

Subjects. Medical & Nursing.

Company. About Us.

Find Us.

Explanation:

6 0
2 years ago
What is the maximum number of elements that will be visited by the binary search algorithm when searching a sorted 45-element ar
sergey [27]

The max nukber of elements visited will be 6.

6 0
2 years ago
what company is credited with solving a problem by creating a program that would work on all computers
seropon [69]

Answer:

The General Problem Solver (GPS) is a particular computer program created in 1957 by Herbert Simon, J. C. Shaw, and Allen Newell intended to work as a universal problem solver, that theoretically can be used to solve every possible problem that can be formalized in a symbolic system, given the right input configuration

Explanation:

7 0
3 years ago
Back wit another one, help !?<br><br>these are two different questions btw
trapecia [35]
Question 1: Best way is option 1, Worst way is option 4.

Question 2: Best way is option 4, Worst way is option 3

7 0
2 years ago
Other questions:
  • #include &lt;iostream&gt;
    9·1 answer
  • The IBM nine-track tapes that became the industry standard for storage for three decades had several sizes , the most common bei
    13·1 answer
  • Write an expression that computes the integer average of the int variables exam1 and exam2 (both declared and assigned values).
    15·1 answer
  • While troubleshooting a network connection problem for a coworker, you discover the computer is querying a nonexistent DNS serve
    13·1 answer
  • A ______________ is a way of taking a screenshot or a picture of your computer screen. ​
    14·1 answer
  • Why do Selection Sort and Insertion Sort’s outer loops run 11 iterations if there are 12 elements in the array?
    7·1 answer
  • Select three advantages of cloud computing.
    10·1 answer
  • Please NEED HELP ASAP WILL MARK BRAINLIEST ONLY #8
    8·1 answer
  • 2. How does the internet give us the ability to communicate?
    15·1 answer
  • What is the value of x after running this code?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!