about | help | code help+videos | done | prefs |
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) |
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