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

 

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

Write a method that returns the specified digit 'digitNum' in the number 'num'. For example, if num=123456 and digitNum=2, return a 5 since 5 is the second digit (counting from the right). So the one's place is digit number 1, the ten's place is digit number 2, etc. If digitNum is greater than the number of digits in the number, return a zero. Look at the test data for further examples. You may choose to use the Math.pow operator. That operator returns a double, so you may need to type-cast it to int. Or you can choose to write your own helper-method for finding powers of ten. As preconditions, you may assume that num>0 and digitNum>0.


mar27_2017_APSLHL_getDigit(1042578, 7) → 1
mar27_2017_APSLHL_getDigit(457, 1) → 7
mar27_2017_APSLHL_getDigit(82493, 2) → 9

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

public int mar27_2017_APSLHL_getDigit(int num, int digitNum) { }

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

Copyright Nick Parlante 2017 - privacy