Skip to content

Instantly share code, notes, and snippets.

@V0L0DYMYR
Created March 10, 2015 12:06
Show Gist options
  • Select an option

  • Save V0L0DYMYR/6cc766538bc816c3d938 to your computer and use it in GitHub Desktop.

Select an option

Save V0L0DYMYR/6cc766538bc816c3d938 to your computer and use it in GitHub Desktop.
DigitsSum.java
public class DigitsSum {
public static void main(String[] args) {
if (args.length > 0) {
int num = Integer.parseInt(args[0]); // 123
int result = 0;
while (num > 0) {
result += num % 10;
num /= 10;
}
System.out.println(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment