Skip to content

Instantly share code, notes, and snippets.

@JIghtuse
Created October 21, 2015 13:41
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 JIghtuse/012f2f6989a47a903727 to your computer and use it in GitHub Desktop.
Save JIghtuse/012f2f6989a47a903727 to your computer and use it in GitHub Desktop.
Horrible digit counting Java class
class DigitCounter {
public static int getCountsOfDigits(int n)
{
if (n > 999999999)
return 10;
if (n > 99999999)
return 9;
if (n > 9999999)
return 8;
if (n > 999999)
return 7;
if (n > 99999)
return 6;
if (n > 9999)
return 5;
if (n > 999)
return 4;
if (n > 99)
return 3;
if (n > 9)
return 2;
if (n > -1)
return 1;
/* FIXME: negative values? */
return 0;
}
public static void main(String args[])
{
System.out.println(getCountsOfDigits(0));
System.out.println(getCountsOfDigits(1));
System.out.println(getCountsOfDigits(10));
System.out.println(getCountsOfDigits(100));
System.out.println(getCountsOfDigits(1000));
System.out.println(getCountsOfDigits(10000));
System.out.println(getCountsOfDigits(100000));
System.out.println(getCountsOfDigits(1000000));
System.out.println(getCountsOfDigits(10000000));
System.out.println(getCountsOfDigits(100000000));
System.out.println(getCountsOfDigits(1000000000));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment