Convert number to string and then use the charAt() method.
class X{
static char digit(int a,int n)
{
String x=a+"";
return x.charAt(n-1);
}
public static void main(String[] args) {
System.out.println(X.digit(123, 2));
}
}
You may want to double check that the nth position is within the length of the number:
static char digit(int a, int n) {
String x = a + "";
char digit='\0' ;
if (n > 0 && n <= x.length()) {
digit = x.charAt(n - 1);
}
return digit;
}