Created
August 25, 2017 05:50
-
-
Save mrisney/18d72b6ba1d8a1fdf5fc513f9f79d762 to your computer and use it in GitHub Desktop.
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
public class DigitCounter { | |
public static void main(String[] args) { | |
int total = 0; | |
for (int count = 1; count <= 1000000; count++) { | |
int[] digits = Integer.toString(count).chars().map(c -> c -= '0').toArray(); | |
for (int d : digits) { | |
total = total + d; | |
} | |
} | |
System.out.println("total = " + total); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment