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 step is first in changing the proofing language of an entire document?
Genrish500 [490]
Select the whole document by pressing Ctrl+a.
7 0
3 years ago
i any company owner (related to medical) is reading this question plz tell me what should i do to get a job as early as posible
mr_godi [17]
My sister works at Mayo and she says come in any time to any Mayo Clinic and say “ I need a job interview stat!”
8 0
3 years ago
Write, run, and test a MARIE assembly language program.The program should allow the user to input 8 numbers and find the smalles
STatiana [176]

The language program is as follows:

<u>Explanation:</u>

ORG 100   / Calculation of the maximum

Load First /loading 1st array member

Store Next /address of next pointer,stores

Load Array /Loading 1st element

Store Max /maximum value with 1st element

Loop, Clear

AddI Next /Load next element!

Subt Max /Comparing with the maximum once

Skipcond 000 /If negative ->skip

Jump NewMax /If not negative ->max value

NextIdx, Load Next

Add One /pointer++

Store Next

Load Count /counter--

Subt One

Skipcond 800 /counter is positive ->same proceeding

Jump Print /else - printing the result

Store Count /counter decresed and stored

Jump Loop

NewMax, Clear / new maximum value

AddI Next

Store Max

Jump NextIdx

Print, Load Max

Output

Halt /Terminate program

First, Hex 11E /starting is location 11E(change as per...,as code changes don't forget to change it too)

Next, Hex 0 /next element index (memory location)

Max, Dec 0 /maximum value

Count, Hex 8 / loop counter decreases

One, Dec 1 /Loop stops

say array:

[Dec -5, Dec 15, Dec -17, Dec 20, Dec -23, Dec 12, Dec 130, Dec -12]

4 0
3 years ago
Holly needs to create an online survey to find out what people want and is
Dahasolnce [82]

Answer:

The correct answer is (A).The server application will allow the customers to select their  answers on the survey.

Explanation:

Since Holly needs to design an online survey which is a web based application, in finding out what people need or want, In this process, the role or function of the server is to enable customers to select their own choice of answers on the survey that will be created online.

4 0
3 years ago
Always adjust mirrors after adjusting your seat.<br> a. True<br> b. False
almond37 [142]
<span>True - it's important to always adjust mirrors after adjusting the position of your seat in the car when driving. This is essential to ensure you have a good view of the road and are able to spot possible hazards and park correctly.</span>
4 0
3 years ago
Read 2 more answers
Other questions:
  • A storyboard is an example of an implementation tool.<br><br> A.<br> True<br><br> B.<br> False
    8·2 answers
  • Need this answered quickly, 40 PTS!
    15·2 answers
  • In Java Write a program that prompts the user for a name (any String value would work for testing), and print a hello message to
    15·1 answer
  • Write down the pseudo code of a program that calculates the Body Mass Index (BMI) of
    9·1 answer
  • A company gives you a document to review. This document lays out the strengths and weaknesses of a proposed business venture. It
    13·1 answer
  • Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with e
    11·1 answer
  • Brake fluid is made up of a chemical that:
    13·2 answers
  • Ayudaa, 5 ejes de sistemas tecnológicos
    5·1 answer
  • Convert 128 GB into KB​
    8·2 answers
  • An animation of a person standing with their arms extended out to their sides. There are 3 dimensional boxes around the torso of
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!