stringLengths

Category: Arrays
Author: Benson Limketkai
Book Chapter: 7.2
Problem: stringLengths
Write a method named stringLengths that takes an array of strings as a parameter and returns an array of integers whose elements are the lengths of the corresponding strings in the array parameter.

For example, given the following arrays:

     String[] array1 = { "you", "say", "goodbye", "and", "i", "say", "hello" };
     String[] array2 = { "i", "love", "CSE", "142" };
     String[] array3 = { "thisisaverylongstring" };
     String[] array4 = { "strings", "strings", "everywhere" };

Calling stringLengths will result in the following values:

     +-----------------------+-------------------------+
     | Call                  | Value Returned          |
     +-----------------------+-------------------------+
     | stringLengths(array1) | { 3, 3, 7, 3, 1, 3, 5 } |
     | stringLengths(array2) | { 1, 4, 3, 3 }          |
     | stringLengths(array3) | { 21 }                  |
     | stringLengths(array4) | { 7, 7, 10 }            |
     +-----------------------+-------------------------+

(You will get the +1 point as long as you write anything that appears to have taken more than a moment to write.)