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

 

ted_mcleod@fuhsd.org java_practice_final_arrays > sumMultiples
prev  |  next  |  chance

Return the sum of all integers in the given array that are multiples of either the next or the previous integer (if they exist); except if the number is more than 10 times the neighboring value, then it does not count as a multiple of that neighbor. All the numbers will be positive integers (no zeros or negative numbers)

Example: {1, 2, 6, 72, 6, 36, 4, 7} returns 44 because 2 + 6 + 36  = 44

Detail: 1 is not a multiple of 2 so it is NOT included in the sum.
        2 is a multiple of 1 so it IS included in the sum.
        6 is a multiple of 2 so it IS included in the sum.
        72 is a multiple of 6 but it is more than 10 times 6 so is NOT included.
        6 is not a multiple of 72 or 36 so it is NOT included.
        36 is a multiple of 6 (and 4) so it IS included.
        4 is not a multiple of 36 or 7 so it is NOT included.
        7 is not a multiple of 4 so it is NOT included.

Hint: Use the modulus operator (%) to test whether a number is divisible by another number.

sumMultiples([1, 2, 6, 72, 6, 36, 4, 7]) → 44
sumMultiples([16, 2, 8, 7, 1, 4]) → 35
sumMultiples([1, 2, 4, 4, 8, 16, 32, 32, 64]) → 162

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

int sumMultiples(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

Copyright Nick Parlante 2017 - privacy