method returns the value of the digit that is position places from the right in the decimal representation of n.
e.g
Enter Number: 8574
What digit do you want? 2
The digit is 5
This is what i got so far . dont' really understand why it is not working.
code: |
class POSITION {
public static void main(String[] args) {
int n, position;
System.out.println("number");
n=In.getInt();
System.out.println ("position");
position=In.getInt();
digit(n,position);
}
public static int digit(int n, int position) {
if (position==2) {
for (int i=1; i<=position; i++){
position=n%10;
n=n/10;
}
}
return position;
}
}
|