Challenge 3: Sum of Digits in an Integer
In this challenge, you will implement a method which will return the sum of digits in an integer.
We'll cover the following
Problem statement
Implement a method in Java called sumOfDig which will return the sum of the digits in an int
variable passed to it.
Method Prototype
int sumOfDig(int var)
Sample input
var = 3557
Sample output
sum = 3 + 5 + 5 + 7 = 20
Pictorial Representation
Get hands-on with 1400+ tech skills courses.