java字符串移位函数

问题遇到的现象和发生背景

将一个字符串的子串在字符串内移动,不改变原有的字符串次序

用代码块功能插入代码,请勿粘贴截图

public class Test11 {
    public static void main(String[] args) {
        String s = "abcdefgh";
        //int n =s.length()-2; //向右移2int n = 2; //向左移2char[] 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;
    }
}