Ask Question
14 January, 08:57

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.

+2
Answers (1)
  1. 14 January, 10:47
    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?
Find 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 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