loljustplaying
Beta member
- Messages
- 3
Ok guys. I'm currently in high school and i have this final exam project i have to do.
Somehow, the old thread got deleted and i can't find the code anymore. This is the last part of the project.What i have to do is:
> Write a method
public static int sumDigits(int num)
The sumDigits method should calculate and return the sum of all the digits in the number that is passed to it. For example, if I call sumDigits(1234), the method should return the value 10 ( 1+2+3+4) . sumDigits does not print anything to the screen.
Then, write a simple main method to test sumDigits. It should allow the user to input a number, call the sumDigits method, and print out the result for the user to see in the format:
The sum of the digits in (number) is (answer).
Someone coded this up in C++ code... but unfortunately, i know nothing about C++...
Help coding this would be GREATLY appreciated.
Somehow, the old thread got deleted and i can't find the code anymore. This is the last part of the project.What i have to do is:
> Write a method
public static int sumDigits(int num)
The sumDigits method should calculate and return the sum of all the digits in the number that is passed to it. For example, if I call sumDigits(1234), the method should return the value 10 ( 1+2+3+4) . sumDigits does not print anything to the screen.
Then, write a simple main method to test sumDigits. It should allow the user to input a number, call the sumDigits method, and print out the result for the user to see in the format:
The sum of the digits in (number) is (answer).
Someone coded this up in C++ code... but unfortunately, i know nothing about C++...
Help coding this would be GREATLY appreciated.