Hi, I can suggest you the following piece of code
-------------------------------------------------
for (int i = 0; i < str.length(); i++) {
for (int j = i + 1; j < str.length(); j++ ) {
if (str.charAt(i) > str.charAt(j)) {
replaceChar1 = str.charAt(i);
replaceChar2 = str.charAt(j);
str.setCharAt(i, replaceChar2);
str.setCharAt(j, replaceChar1);
}
}
}
-------------------------------------------------
Type of str here is StringBuffer
Best,
Anna
|