Problem Statement
A letter-string is composed of letters ('A'-'Z','a'-'z') and dashes ('-'). The
length of a letter-string is the number of characters in it not including dashes
(in other words, the number of letters in the string). Given a list of
letter-strings you will return the sum of their lengths.
Create a class LetterStrings that contains the method sum, which takes a String[], s, and returns an int representing the sum of the lengths of the given letter-strings.
Create a class LetterStrings that contains the method sum, which takes a String[], s, and returns an int representing the sum of the lengths of the given letter-strings.
Definition
- Class:
- LetterStrings
- Method:
- sum
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int sum(String[] s)
- (be sure your method is public)
Constraints
- s will contain between 1 and 50 elements, inclusive.
- Each element of s will have length between 1 and 50, inclusive.
- Each element of s will contain only letters ('A'-'Z','a'-'z') and dashes ('-').
Examples
{"-"}Returns: 0
{"A"}Returns: 1
{"-----Abc"}Returns: 3
{"-A-B-C-D", "--------EFGHI", "JKLMNOPQR", "---STU-VW-XYZ"}Returns: 26