i have the following code that reads user input characters and displays the string entered in reverse order.
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ReverseString {
public String reverse(String arg)
{
String input = null;
if (arg.length() == 1)
{
return arg;
}
else
{
//extract the last character entered
String lastChar = arg.substring(arg.length()-1,arg.length());
//extract the remaining characters
String remainingChar = arg.substring(0, arg.length() -1);
input = lastChar + reverse(remainingChar);
return input;
}
}
}
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class TestReverseString
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter string values.");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputData;
inputData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println(rs.reverse(inputData));
}
}
If abc123 is entered, 321cba is returned. How do I get the program to return three two one cba? In other words, I need to spell out the numeric values that are entered.
thanks for your time fellas