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

 

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

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)

public int abc1countDigits(int num, int targetDigit) { }

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

Copyright Nick Parlante 2017 - privacy