about | help | code help+videos | done | prefs |
Write a method that returns the sum of all the digits in the double parameter 'num'. As a precondition, you may assume that 'num' will have a value such that it will not be converted to scientific notation when converted to a string. (That is also a hint regarding one possible approach to doing this problem!). The value of 'num' can be positive, negative, or even zero. The value that is returned should be the sum of all the digits, ignoring any special symbols such as '-' and '.'. Look at the test data for examples. test2023_10_05_HL_digitSum(2.0000071) → 10 test2023_10_05_HL_digitSum(214.3250004) → 21 test2023_10_05_HL_digitSum(-60.00001) → 7 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 220
Copyright Nick Parlante 2017 - privacy