Question

onsider the following method that is intended to return the sum of the elements in the...

onsider the following method that is intended to return the sum of the elements in the array key.

public static int sumArray(int[] key) 
{ 
 int sum = 0; 
 for (int i = 1; i <= key.length; i++) 
 { 
      /* missing code */ 
 } 
 return sum; 
}

Which of the following statements should be used to replace /* missing code */ so that sumArray() will work as intended?

a. sum += key[i];

b. sum = key[i];

c. sum += sum + key[i - 1];

d. sum += sum + key[i];

e. sum += key[i - 1];

0 0
Add a comment Improve this question Transcribed image text
Answer #1

e. sum += key[i - 1];

Add a comment
Know the answer?
Add Answer to:
onsider the following method that is intended to return the sum of the elements in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT