java - Extract ones and tens from an integer value -
this question has answer here:
- how separate digits of int number? 20 answers
i think math little bit tricky in java. lets have integer value of 203 , want extract 0 , 3. me, easiest way have intat(1) , intat(2) or able extract left(203,1) retrieve "2" , subract with: 203 - (2 * 100).
anyway think got solution, see codeblock below:
string th = integer.tostring(203); int th2 = integer.valueof(th); string th3 = th.charat(1) + "" + th.charat(2); int thrown_card_two_post = integer.valueof(th3); system.out.println(thrown_card_two_post); is there more efficient way accomplish this?
i think best way smaller large.
so first, take modulus 10 last digit. if don't know, modulus 10is remainder after division 10 , can expressed
203 % 10.after have last digit, subtract total , take modulus 100 second digit.
repeat digits.
if don't need digits, specific one, can first divide skip couple steps.
Comments
Post a Comment