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
Which technique is best suited to create technical drawings?
Tema [17]

Answer:

Mechanical pencils.

Clutch pencils.

Technical pens.

Rulers.

Compass.

Drawing boards.

Erasers.

Sharpeners.

Explanation:

'What makes a great Technical Drawing? ' Technically correct, accurate, complete, consistent and unambiguous. Check the brief (a lot – and at all stages of the drawing process).

8 0
2 years ago
Artificial intelligence (AI) and machine learning are especially important during which security information and event managemen
Juli2301 [7.4K]

Answer:

hueiweke

Explanation:

5 0
2 years ago
15
iVinArrow [24]

I believe that the answer is A: Extension but I am not 100% sure, hope this helps.

7 0
3 years ago
Read 2 more answers
Which is true about TCP and UDP? Choose two answers.
vichka [17]

Answer:

TCP is a connection-oriented protocol

UDP does not acknowledge a receipt of data

Explanation:

TCP (Transmission Control Protocol) is a protocol to transfer data, this is one of the most important protocols on the entire internet, this method was implemented from the beginning of the network.

UDP (User Datagram Protocol) this is a protocol faster than TCP because this method doesn't establish a connection to sent data, in this case, always sent data, but TCP is more secure than UDP, and for that UDP is used to transfer music or videos, and TCP websites and database.

UDP doesn't need acknowledgment is done by UDP, is only concerned with speed.

7 0
3 years ago
For an alternative to the String class, and so that you can change a String's contents, you can use_________ .
mr_godi [17]

Answer:

c. StringBuilder

Explanation:

An alternative to the String class would be the StringBuilder Class. This class uses Strings as objects and allows you to mix and match different strings as well as adding, removing, implementing,  and modifying strings themselves as though they were similar to an array. Unlike the string class StringBuilder allows you to modify and work with a combination of strings in the same piece of data as opposed to having various objects and copying pieces which would take up more memory.

7 0
3 years ago
Other questions:
  • Tommy has hired a marketing company to create a billboard advertisement
    11·2 answers
  • The prediction that the number of transistors on a chip would double about every two years is known as ________. Metcalfe's law
    6·1 answer
  • What does computer means?
    13·2 answers
  • • What is the difference between primary storage, secondary storage, and off-line storage
    10·1 answer
  • An electronic braille embosser that translates text from a braille keyboard to a printer:
    10·1 answer
  • What is the purpose of the domain name​
    5·1 answer
  • Write an HTML document which contains two text fields, a button, and a div. The first text field should be labeled “Temperature”
    10·1 answer
  • COMPUTER CODING
    5·1 answer
  • What function is used to return the results in column D?
    11·1 answer
  • PLEASE HELP ASAP!! Timed test!!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!