The other way is convert the digit into array and return the nth index
static char digit(int a,int b)
{
String x=a+"";
char x1[]=x.toCharArray();
int length=x1.length;
char result=x1[length-b];
return result;
}
Now run from your main method like this way
System.out.println("digit answer "+digit(1254,3));
output
digit answer 2