Limited access

Upgrade to access all content for this subject

Consider the following code segment.

int[] nums = {5, 10, 6, 2, 8, 1};
int sum = 0;

for (int i=1; i<nums.length; i++)
{
    if (nums[i-1]>nums[i])
        sum += nums[i-1];
    else 
        sum += nums[i];
}
System.out.println(sum);

What is printed as a result of executing the code segment?

A

24

B

35

C

42

D

51

E

16

Select an assignment template