public class ReverseString {
private static String str = "world";
public static void main(String[] args) {
char[] charArray = str.toCharArray();
String strReverse= toReverse( charArray);
System.out.println(strReverse);
}
public static String toReverse(char[] charArray){
char temp ;
int startIndext =0;
int endIndex = charArray.length;
for(;startIndext<endIndex;startIndext++,endIndex--){
temp =charArray[startIndext];
charArray[startIndext]=charArray[endIndex];
charArray[endIndex] =temp;
}
return str;
}
} |