You can pick up the third digit.
int d3 = x / 100;
And the second digit:
int d2 = (x / 10) % 10;
Note: I’m assuming 100 <= x <= 999
Update: I wanted to search for a fast solution giving the number of digits and this question gave a (potentially) good solution:
x = (int)Math.abs(x); // this is for negative numbers
int digits = (int)Math.log10(x) + 1;
This extends the hypothesis of 100 <= x <= 999
:
int div = Math.pow(10, digits - 1);
int firstDigit = x / div;
div /= 10;
int secondDigit = (x / div) % div;
This should work for any x != 0
. There may be faster solutions though.