Ask Question

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.

+4
Answers (1)
  1. 20 April, 04:49
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers