Sunday, March 09, 2014

Code for reversing a string in Java

package com.reverse;

public class ReverseWords {

public static String reverseTheString(String input)
{
if(input.length()>1)
return input.substring(input.length()-1, input.length()) + reverseTheString(input.substring(0,input.length()-1));
else
{
return input.substring(0, 1);
}

}
public static void main(String args[])
{
System.out.println(reverseTheString("hello"));
}

}