Problem Statement
The smallest digit in an integer is defined to be the digit closest to 0 out of
the possible 0 - 9.
Create a class Digits that contains the method sumDigits, which takes in the parameter int[], numbers, and returns the sum of the smallest digit from all the numbers.
Create a class Digits that contains the method sumDigits, which takes in the parameter int[], numbers, and returns the sum of the smallest digit from all the numbers.
Definition
- Class:
- Digits
- Method:
- sumDigits
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int sumDigits(int[] numbers)
- (be sure your method is public)
Notes
- the integer 0 is seen as having a smallest digit of 0
- no integers will have leading 0's (99 will never be seen as 099)
Constraints
- numbers has between 1 and 20 elements, inclusive
- Each element of numbers is between -1000 and 1000, inclusive
- All integers are considered to be base 10, and will only have digits 0 - 9
Examples
{987}Returns: 7
7 is the smallest digit out of the possible digits 7, 8, and 9.{987, -990}Returns: 7
7 is the smallest digit of 987, and 0 is the smallest digit from -990. 7 + 0 = 7{48, -88, 46, -45, 22}Returns: 22
{675,-946,999,18}Returns: 19