// the recursive solution
public static String reverse(String str) {
// if our string is "" then that reversed is ""
if (str.length() == 0) return "";
// else put the first character on the end of our
answer and recursively call on all but the first character
else return reverse(str.substring(1,str.length()) +
str.substring(0,1);
}
// the non-recursive solution
public static String reverse(String str) {
// start our result as an empty string
String result = "";
for (int count = 0; count < str.length();
count++)
// add the current character
to the start of the result
result = str.substring(count,
count+1) + result;
// return the result
return result;
}