Ask Question

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. 1 July, 16:56
    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 & 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