class Test{
public static void main (String[] args){
String str ="abcdef";
String result = reverse(str);
System.out.println(result);
}
public static String reverse(String str){
int length = str.length();
if(length<=0)
return null;
char[] src = str.toCharArray();
char[] result = new char[length];
for(int i=0; i<result.length; i++){
result[i]=src[length-i-1];
}
return new String(result);
}
}
|
|