The code below, as it starts from last character of the string, the endIndex will be beyond the string, as a result, the first iteration in case of startIndex = st.length() - 1 will never been executed.
for (int startIndex = st.length() - 1; startIndex >= 0; startIndex–) {
for (int endIndex = startIndex + 1; endIndex < st.length(); endIndex++) {
I am wondering maybe start from st.length() -2 could make more sense? any suggestion? Thanks.
for (int startIndex = st.length() - 2; startIndex >= 0; startIndex–) {
for (int endIndex = startIndex + 1; endIndex < st.length(); endIndex++) {