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

 

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

Write a method that returns an array indicating how many times each digit occurs in the number 'num'. The index of the array indicates the digit, and the value of the array at that index indicates how many times that digit occurred. For example, if 'num' is 577355, you would return the array {0,0,0,1,0,3,0,2,0,0} because '3' occurs once, '5' occurs 3 times, and '7' occurs 2 times. In solving this problem, you are NOT allowed to use any of the following things: NOT allowed: strings or string methods; NOT allowed: ArrayList; NOT allowed: use of switch-case; NOT allowed: more than two if statements; NOT allowed: more than two ternary conditionals; As a precondition, you may assume that 'num'>0 Look at the test data for examples.


test2024_02_08_APP1SLHL_digitCounts(500992) → [2, 0, 1, 0, 0, 1, 0, 0, 0, 2]
test2024_02_08_APP1SLHL_digitCounts(55) → [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]
test2024_02_08_APP1SLHL_digitCounts(84471) → [0, 1, 0, 0, 2, 0, 0, 1, 1, 0]

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

public int[] test2024_02_08_APP1SLHL_digitCounts(int 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: 280

Copyright Nick Parlante 2017 - privacy