Given a string, return a version where all the "x" have been removed. Except an "x" at the very start or end should not be removed.
public String stringX(String str) { String a = ""; for (int i = 0; str.length()>i; i++) { if (!(i > 0 && i < (str.length()-1) && str.substring(i,i+1).equals("x"))) a = a + str.charAt(i); } return a; }
Question is in regards to the process that this statement is fulfilling for length. i < (str.length()-1) I don't understand why, without this condition, it wont check for an x in the very last variable which will return the string without the final x character if there is one.