欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

把字符串abcdef旋转2位得到字符串cdefab

程序员文章站 2022-05-19 16:27:50
...

public class RightShift { public static void main(String args[]) { char[] c = { 'a', 'b', 'c', 'd', 'e' }; for (int i = 0; i c.length; i) { System.out.print(c[i]); } for (int i = 0; i 2; i) { char temp = c[0]; for (int j = 0; j c.length -

public class RightShift {

public static void main(String args[]) {

char[] c = { 'a', 'b', 'c', 'd', 'e' };

for (int i = 0; i System.out.print(c[i]);
}

for (int i = 0; i char temp = c[0];
for (int j = 0; j c[j] = c[j + 1];
}
c[c.length - 1] = temp;
}
System.out.println();
for (int i = 0; i System.out.print(c[i]);
}
}

}