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

 

konstans@stuy.edu > sumOddDigits
prev  |  next  |  chance

Write a Java function named sumOddDigits that takes a single positive integer as input and returns the sum of all odd digits in that number.
e.g. sumOddDigits(4936827) returns 19
The digits are 4, 9, 3, 6, 8, 2, 7 (You learned in class how to split a number into digits using modulo and division)
Odd digits: 9, 3, 7
9 + 3 + 7 = 19
The input number is a positive integer (greater than 0)
You may use arithmetic operators (%, /, etc.)
Do not use arrays or strings to process the number


sumOddDigits(7) → 7
sumOddDigits(2) → 0
sumOddDigits(13) → 4

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

public int sumOddDigits(int number){ }

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