//Reverse The String
class ReverseString
{
public static void main(String A[])
{
String str1="amit";
StringBuffer str2=new StringBuffer("");
int len=str1.length();
for(int i=len-1;i>=0;i--)
{
str2.append(str1.charAt(i));
}
System.out.println("Reverse of String is..."+str2);
}
}
// -----------------OR-----------------------------
//public class ReverseString
//{
// public static void main(String[] args)
// {
// String str = "What's going on?";
// System.out.println(ReverseStringTest.reverseIt(str));
// }
//}
//class ReverseStringTest
//{
// public static String reverseIt(String source)
// {
// int i, len = source.length();
// StringBuffer dest = new StringBuffer(len);
//
// for (i = (len - 1); i >= 0; i--)
// {
// dest.append(source.charAt(i));
// }
// return dest.toString();
// }
//}
No comments:
Post a Comment