Question: 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

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 code has a bug (or perhaps bugs?) in it. TASK: Fix the bug(s).

static int sum(int[] nums) { int total = 0; for(int num : nums) { // for-each loop total += num; } }

Sample Input:

1 2 3 4 5

Sample Output:

15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!