Ask Question
21 July, 03:16

Write a method, getSecondLine, that is passed a String argument and that returns the second line, without its newline character. (Recall that lines are terminated with the "/n" character.) Assume that the argument contains at least two complete, newline-terminated lines.

+5
Answers (1)
  1. 21 July, 07:03
    0
    The answer to this question can be given as:

    Method definition:

    String getSecondLine (String aString) / /define function getSecondLine ()

    {

    return aString. substring (aString. indexOf ("/n") + 1, aString. indexOf ("/n") + 1 + aString. substring (aString. indexOf ("/n") + 1, aString. length ()). indexOf ("/n"));

    //return value.

    }

    Explanation:

    The working of the function definition can be given as:

    In the above function definition we define getSecondLine () function.

    This function returns string value because we use the string return type.

    In this getSecondLine () function we pass the a string variable that use substring function which return a string into parts.

    In the substring function we use the indexOf function that is used to return the position of the string.

    In this method definition, it will return the string value into the new lines.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a method, getSecondLine, that is passed a String argument and that returns the second line, without its newline character. (Recall ...” 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