Ask Question
10 September, 02:00

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.

+2
Answers (1)
  1. 10 September, 03:05
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers