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

 

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

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)

public int test2023_10_05_HL_digitSum(double num) { }

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

Copyright Nick Parlante 2017 - privacy