Ask Question
25 September, 08:24

Write a static method that takes an array of Strings and returns an integer. Determine the longest String contained within the array. Return the number of characters in that String.

+1
Answers (1)
  1. 25 September, 11:08
    0
    static int detlongeststring (string a[30])

    {

    int i=0, k=0;

    int len1 = strlen (a[0];

    for (i=0; i<=30; i++)

    {

    len=strlen (a[i]);

    if (len1>=len)

    {

    continue ();

    }

    else

    {

    k=i;

    }

    }

    cout<<"The longest string is:"<
    cout<<" The string length is:"<
    return strlen (a[i]);

    }

    We are passing array of strings as argument to function. Now we compare strlen of each string with all and find the longest string, and we store the index in K. Then we print this string that is the lengthiest, and which has index k definitely.

    Explanation:

    The answer is self explanatory.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a static method that takes an array of Strings and returns an integer. Determine the longest String contained within the array. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers