I am trying to print the string without its middle character, but I am not getting the required output.
public class StringIndexEliminator {
public static void main(String[] args) {
String str = "CARS";
int l = str.length();
int s = (l+1)/2;
System.out.println(l);
StringBuffer sb = new StringBuffer(str);
System.out.println(sb.deleteCharAt(s).toString());
}
}
No need to use a stringBufffer (there is no race conditions) use the StringBuilder and then remove the char at length/2