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
7.3 Code Practice edhesive
sladkih [1.3K]

Answer:

def print_sum(a,b,c):

 print(a+b+c)

one = int(input("Enter the 1st number: "))

two = int(input("Enter the 2nd number: "))

three = int(input("Enter the 3rd number: "))

print_sum(one,two,three)

Explanation:

hope this helped :)

5 0
2 years ago
Read 2 more answers
Who's better Kapkan or Tachanka?
navik [9.2K]
If you want fun operator, get chanka, if you want good operator, get kapkan it also depends if depends you are a stationary man who likes big guns or a mobile man who likes traps
4 0
3 years ago
what determines the best types of sketch or drawing to complete when you want to communicate your idea about a solution to a tec
Mekhanik [1.2K]
It depends on the problem. If you are solving a conplex one or simple
8 0
3 years ago
Paragraph: Read the following two e-mail messages. In three to five sentences, explain why E-mail B is the more appropriate work
exis [7]
E-mail B is the more appropriate workplace e-mail because it’s straightforward, polite, and professional. E-mail A was more accusatory and aggressive, and many people don’t like when they’re being yelled at or accused of something and, as a result, this person may start to dislike that coworker. However, the second e-mail was more polite and made the receiver think of them as a respectful person so that they’re happy to help them out.
4 0
3 years ago
In a switch statement, if a break statement is missing, _______________. Select one: a. the default case is automatically execut
Aleks [24]

Answer:

c. execution falls through the next branch until a break statement is reached

Explanation:

In a switch statement, if break is missing, then program continues to the next cases until it finds a break statement.

Consider the following example!

Example:

#include <iostream>

using namespace std;

int main()

{

  int choice = 1;

  switch (choice)

  {

      case 1:

      printf("This is case 1, No break\n");

      case 2:

      printf("This is case 2, No break\n");

      case 3:

      printf("This is case 3, with break\n");

      break;

      default: printf("Error! wrong choice\n");

  }

  return 0;

}

Output:

This is case 1, No break

This is case 2, No break

This is case 3, with break

We have 3 cases here and case 1 and 2 don't have break statements, only case 3 has a break statement.

We called the case 1, then program continued to case 2,  and finally to case 3 where it finds the break statement and terminates.

Therefore, we conclude that in a switch statement, if a break statement is missing, then execution falls through the next branch until a break statement is found.

8 0
3 years ago
Other questions:
  • It takes an older computer twice as long to send out a company's email as it does a newer computer. Working together, it takes t
    15·1 answer
  • Samantha writes technical content for a webpage and uploads it to the webpage. What should she do to ensure that the content, wh
    11·2 answers
  • The ___ is the primary storage device of a personal computer. hard drive RAM ROM compact disc
    6·1 answer
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • If you have a mix of 32-bit and 64-bit versions of windows, which architectures should you add a unattended installation file fo
    7·1 answer
  • You have a new phone. What determines what type of messages you can send?
    15·1 answer
  • What is drop shipping and how it works on amazon?
    12·1 answer
  • Ns.office.com/Pages/ResponsePage.aspx?id=bd8
    9·2 answers
  • Write program to read 10 random numbers, then find how many of them accept division by 4,
    6·1 answer
  • What is Virtual Storage Configuration and Management, as well as Virtual Machine Management?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!