Hello everyone,
how can i replace each letter for example "abcde" to "edcba" with StringBuilder only and without the reverse tool
this is what i tried:
the output is:edcde with i understand why its wrong ,the last two letters already swap so it didnt take from the original str.StringBuilder str=new StringBuilder("abcde"); int indexBegin=0; int indexEnd=4; for(int i=0;i<str.length();i++){ str.setCharAt(i, str.charAt(indexEnd)); indexEnd--; } System.out.println(str);
any thoughts how to improve it?
thanks:}