Given an array of characters. How would you reverse it.

 

public class Reverse {

 public static void main(String args[]) {
 
  StringBuilder array = new StringBuilder();
  array.append("abcderr");
 
  for(int i=0;i<array.length()/2;i++)
  {
   char temp=array.charAt(i);
 
   array.replace(i, i+1,array.charAt(array.length()-1-i)+"");
   array.replace(array.length()-i-1,array.length()-i,temp+"");
 
  }
 
  System.out.print(array);
 
 }

}


 

 

你可能感兴趣的:(Given an array of characters. How would you reverse it.)