整数のi番目の桁を抽出する
任意の整数の i 番目の桁を抽出します。ここで、i は右から左の順になります。
Python
In [1]: y = lambda x, i: (x/10**(i-1))%10
In [2]: y(8765,3)
Out[2]: 7
Java
/**
* Get the i-th (from right to left) digit of number
* @param number the integer number
* @param i the position, should be greater than 0
* @return the i-th digit of given integer number
*/
public static int getIthDigit(int number, int i)
{
return (number/(int)Math.pow(10, i-1))%10;
}