I'm attempting to scramble two random letters of a string which isn't the first letter, or last two. I'm getting a "String index out of range" error when compiling. I've tried workshopping many different solutions, but nothing seems to work.
For this assignment, we have to use a method and .charAt commands. I've tried creating variables for the two random characters then adding them back into the string flipped, but couldn't get that to work either.
public static String scramble(String input) {
int range = input.length() - 3;
int place = (int)(Math.random() * range);
String newWord = "";
newWord = input.substring(0, place);
newWord = newWord + newWord.charAt(place) + 2;
newWord = newWord + newWord.charAt(place) + 1;
return newWord;
I'm expecting an output of a string with two of its characters scrambled. For example, "Fantastic" would be "Fantsatic", or "Fnatastic".