How can you create a method that returns the value of the digit that is position places from the right in the decimal representation of n.
e.g
Enter Number: 763
What digit do you want? 0
The digit is 3
---------
Enter Number: 8574
What digit do you want? 2
The digit is 5
-----------
This is what i got so far. but it apparently doesn't work. is there anyway to do exponent to a assign value like (10e position)
class position1 {
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) {
for (int i=1; i<=position; i++){
n=n/(int)(10e2);
position=n%( (int)( 10e2) );
System.out.print(position);
}
return position;
}
}
e.g
Enter Number: 763
What digit do you want? 0
The digit is 3
---------
Enter Number: 8574
What digit do you want? 2
The digit is 5
-----------
This is what i got so far. but it apparently doesn't work. is there anyway to do exponent to a assign value like (10e position)
class position1 {
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) {
for (int i=1; i<=position; i++){
n=n/(int)(10e2);
position=n%( (int)( 10e2) );
System.out.print(position);
}
return position;
}
}