about | help | code help+videos | done | prefs |
Without using arrays or strings, write a method that returns the number of occurrences of a particular single digit within a positive integer. For example, the digit 7 occurs 3 times in the number 715773. Two parameters will be passed in. As preconditions, you may assume that 'num' will be positive and 'targetDigit' will be a single digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Return the number of time 'targetDigit' occurs in 'num'. Note that LEADING zeros are NOT counted. abc1countDigits(128142, 1) → 2 abc1countDigits(94200, 4) → 1 abc1countDigits(7218111, 1) → 4 ...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: 280
Copyright Nick Parlante 2017 - privacy