Skip to content

Instantly share code, notes, and snippets.

@LuxXx
Created February 17, 2017 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuxXx/8ebdbf9283985728852f8ed4fea2be16 to your computer and use it in GitHub Desktop.
Save LuxXx/8ebdbf9283985728852f8ed4fea2be16 to your computer and use it in GitHub Desktop.
digitat (left to right)
public static int digitAt(int n, int i) {
// (n mod 10^i)/(10^i-1)
int a = n % (int) Math.pow(10,i); // a = n modulo 10^i
int b = (int) Math.pow(10,i-1); // b 10^-1
return (int) Math.floor(a/b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment