Skip to content

Instantly share code, notes, and snippets.

@mrisney
Created August 25, 2017 05:50
Show Gist options
  • Save mrisney/18d72b6ba1d8a1fdf5fc513f9f79d762 to your computer and use it in GitHub Desktop.
Save mrisney/18d72b6ba1d8a1fdf5fc513f9f79d762 to your computer and use it in GitHub Desktop.
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