StringIndexOutOfBoundsException « string « Java Data Type Q&A

1. Why am I getting a StringIndexOutOfBoundsException when I try to replace `\\` with `\`?

I have to replace \\ with \ in Java. The code I am using is

System.out.println( (MyConstants.LOCATION_PATH + File.separator + myObject.getStLocation() ).replaceAll("\\\\", "\\") );
But I don't know why it is throwing ...

2. StringIndexOutOfBoundsException

This program I'm making isn't compiling right, I keep getting the error: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -9 at java.lang.String.charAt( at pro1.main( Here's my code:

import java.util.*;
public ...

3. Why am I getting java.lang.StringIndexOutOfBoundsException?

I want to write a program that prints words incrementally until a complete sentence appears. For example : I need to write (input), and output:

I need