Im having some problem with this 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.
This is my code:
public String getSecondLine(String input)
return input.substring(input.indexOf("\n"),input.indexOf( input.substring(input.indexOf("\n")-1)));
I am getting this error message:
Exception java.lang.StringIndexOutOfBoundsException: String index out of range: -1 occurred
Can someone help me? Thanks!