将一个字符串的子串在字符串内移动,不改变原有的字符串次序
public class Test11 {
public static void main(String[] args) {
String s = "abcdefgh";
//int n =s.length()-2; //向右移2位
int n = 2; //向左移2位
char[] c = s.toCharArray();
System.out.println(reverse(c,0,n-1));
System.out.println(reverse(c,n,c.length-1));
System.out.println(reverse(c,0,c.length-1));
}
public static char[] reverse(char[] c,int begin,int end){
char temp;
while(end>begin){
temp = c[begin];
c[begin] = c[end];
c[end] = temp;
end--;
begin++;
}
return c;
}
}