//*****************************************
// revstring - recursively reverse a string
// Name:
// Date:
//*****************************************
import java.io.*;
public class RevString
{
//******************************************************
// main method reads a string input by the user and
// calls recursive methods that print string in
//reverse
// and return reversed string
//******************************************************
public static void main(String[] args) throws IOException
{
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (isr);
System.out.println("Enter a String");
String input = stdin.readLine();
System.out.print("The input in reverse is --> ");
rev(input);
System.out.println();
// String strrev = retrev(input);
// System.out.println();
// System.out.println("The returned string is --> " + strrev);
}
// ****************************************************
// recursive method that prints the reverse of a string
// public static void rev (string r)
{
String strRemaining = "1";
String str = String.valueOf®;
int iLen = str.length(); //get length for
indexing substrings
if (iLen <= 1)
System.out.println(str);
else
{
//save the x-1 characters of string
strRemaining = str.substring(0, (iLen - 1));
//put the last character into substring
str = str.substring((iLen - 1), iLen);
//print last character
System.out.print(str);
//revert string back to number
r = Integer.valueOf(strRemaining).intValue();
//call itself recursively
Reverse®;
}
//*****************************************************
// recursive method that returns the reverse of a string
// public static String retrev(String r)
// {
// }
}
}