Created
October 21, 2015 13:41
-
-
Save JIghtuse/012f2f6989a47a903727 to your computer and use it in GitHub Desktop.
Horrible digit counting Java class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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