Basically, I'm trying to integrate the code structure our course textbook tells us to use, which is setting a first, middle, and last part of the string, then printing it using concatenation (structure shown in the code), but get a java.lang.StringIndexOutOfBoundsException.
I have tried messing around with the i and j values in the code, trying to get the index within bounds.
i = keyboard.nextInt();
j = keyboard.nextInt(); // decides letter swap spots
first = word.substring(word.length(),i-1);
middle = word.substring(i+1,j-1);
last = word.substring(j+1,(word.length()-1));
System.out.printf(first + middle + last);
I essentially need the program to swap letter spots of a word (provided by the user) based upon the I and J values. I am getting this error:
java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 7
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3410)
at java.base/java.lang.String.substring(String.java:1883)
(using the word "hello" as my user input example)