Exercise: Digit Sum

Write a console program that calculates the sum of the digits of a number. For example, the sum of the digits of 123 is:

1 + 2 + 3 = 6

Example program output (user input in green):
Enter a number:
5024
The digit sum of 5024 is 11

Hand in instructions

  1. Make sure your program runs correctly.
  2. Hand in your program by uploading Main.java to Moodle.