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
You need to find out more about the fdisk utility and the commands associated with it before you set up a new linux system in ad
lutik1710 [3]

The man utility is a console based program that displays manual pages of other utilities, so for fdisk, you would use man -k fdisk to search for fdisk related manuals

7 0
4 years ago
In excel what happens when rename a sheet from sheet1 to inventory​
makvit [3.9K]

Answer:

Explanation:

The sheet name at the footer of the screen gets changed from sheet1 to inventory.

4 0
3 years ago
Mightier than the waves of the sea is his love for you
Inessa05 [86]

cool but kinda creepy ngl

8 0
3 years ago
If I Uninstall Nba 2k 19 from my ps4 will my career be gone forever?​
Rudik [331]

Answer:

Not unless you have a ps plus membership

Explanation:

Ps plus have cloud storage so if you have ps plus membership,even if you delete 2k19 your data will be saved in the cloud storage therefore your my carrer will not be gone forever!

7 0
4 years ago
Read 2 more answers
If you log into the admin account on windows 10, will the admin be notified ? ​
MrMuchimi
I think with a admin to the window it will be notified
6 0
3 years ago
Read 2 more answers
Other questions:
  • What is binary coded decimal,EBCD and ASCII
    15·1 answer
  • In addition to MLA, what are some other widely used style guides? Check all that apply.
    6·2 answers
  • On an Android device, where can a user find the correct app to use to sync contacts and apps among devices?
    10·1 answer
  • Write the definition of a class Clock. The class has no constructors and three instance variables. One is of type int called hou
    13·1 answer
  • Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is consi
    6·1 answer
  • Assume that sentence is a variable of type String that has been assigned a value. Assume furthermore that this value is a String
    10·1 answer
  • Question 21 pts How many lines should an email signature be? Group of answer choices "5 to 6" "7 to 8" "1 to 2" "3 to 4"
    10·1 answer
  • Anybody know this? Read the following scenario. Using complete sentences, explain which part of the CIA triad has been broken. M
    11·1 answer
  • Hannah wanted to watch a movie. She typed the movie name on the search engine. In result she found the downloadable link of the
    10·1 answer
  • Design a for loop that gets 6 integer numbers from a user, accumulates the total of them, then displays the accumulated total to
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!