About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, April 26, 2010

JAVA(Reverse The String)------------------------------

//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: