id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > quiz2022_03_01_APSLHL_funnySum
prev  |  next  |  chance

Write a method that returns the "funny sum" of an array of integers. The funny sum is equal to the sum of all the numbers in the array, but some of the numbers are added multiple times. For example, given {5,7,2,3}, the "funny sum" is equal to 5+7+2+3 + 7+2+3 + 2+3 + 3 = 37. So each number is added once, then each number except the first number is added again, each time leaving out one more number. This can be done nicely with nested loops, but it also can be done with a single loop if you think about it first! Look at the test data for other examples.


quiz2022_03_01_APSLHL_funnySum([]) → 0
quiz2022_03_01_APSLHL_funnySum([17]) → 17
quiz2022_03_01_APSLHL_funnySum([-4, -10]) → -24

...Save, Compile, Run (ctrl-enter)

public int quiz2022_03_01_APSLHL_funnySum(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 250

Copyright Nick Parlante 2017 - privacy