public class ReverseString {
public static void main(String[] args) {
String str = "abc";
System.out.println(getReverse(str));
}
public static String getReverse(String str)
{
char[] chs = str.toCharArray();
for (int start = 0,end = chs.length-1; start <= end; start++,end--) {
swap(chs,start,end);
}
String str1 = new String(chs);
return str1;
}
private static void swap(char[] chs, int start, int end) {
// TODO Auto-generated method stub
char temp = chs[start];
chs[start] = chs[end];
chs[end] = temp;
}
}
|