For some reason when the string length is zero, it does not come out of the while loop. Can some one help me on this?
static String str1 = "";
public static void reverse(String str) {
while (str.length() > 0) {
str1 = str1 + str.charAt(str.length() - 1);
StringBuffer str_buf = new StringBuffer(str);
str = str_buf.deleteCharAt(str.length() - 1).toString();
reverse(str);
}
System.out.println("String is " + str1);
}