java - Splitting number and grabbing -
if have:
int money; money = 378;
now how many banknotes , coins out this..
sweden has these banknotes: 500, 100, 50, 20 , coins 10, 5, 1
so output wish above money
value:
3x100 , 1x50 , 1x20, 1x5, 3x1
how can this?
think how in real life. you'd probably start off highest denomination bank note, use many of possible (decreasing amount still go), move next highest, etc.
so example, start off 378. how many 500s can use? none. still have 378... how many 100s can use? 3, leaving 78 go. how many 50s can use? 1, leaving 28 go etc.
you'll want sort of collection representing bank notes (and coins) available, , keep track of how money still have represent. think how want represent result too.
Comments
Post a Comment