fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static int getDigit(int x, int idx) {
  11. int digitsCount = (int) Math.log10(x);
  12. int divisor = ((int) Math.pow(10, digitsCount - idx));
  13. if (divisor == 0) return x % 10;
  14. return (x / divisor) % 10;
  15. }
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. System.out.println(Ideone.getDigit(11, 0));
  19. }
  20. }
Success #stdin #stdout 0.08s 54548KB
stdin
Standard input is empty
stdout
1