public class Test{
public static void main(String[] args) {
String str="abcdefg";
int len=str.length();
char ch[]=str.toCharArray();
beforChar(4,ch);
for(int i=0;i<len;i++){
System.out.print(ch[i]);
char temp;
int k=i-1;
for(int j=0;j<k;j++){
temp=ch[j];
ch[j]=ch[k];
ch[k]=temp;
public static void main(String[] args) {
String str="abcdefg";
int len=str.length();
char ch[]=str.toCharArray();
beforChar(4,ch);
for(int i=0;i<len;i++){
System.out.print(ch[i]);
}
}
private static void beforChar(int i, char[] ch) {char temp;
int k=i-1;
for(int j=0;j<k;j++){
temp=ch[j];
ch[j]=ch[k];
ch[k]=temp;
}
}
结果:dabcefg