第十八题
- 功能描述:数组的循环移位,
- 输入:{a,b,c},2
- 输出:{b,c,a}
- 要求实现方法:
// data :待循环数组
// index:移动位数
public String[] getChildren(String[] data,int index) {
//TODO
return null;
}
public class Test {
public static void main(String[] args) {
String[] str = {"a", "b", "c"};
int a = 2;
String[] result = getChildren(str, a);
for (String s: result) {
System.out.println(s);
}
}
public static String[] getChildren(String[] data, int index) {
String[] result = new String[data.length];
for (int i = 0; i < result.length - 1; i++) {
result[i] = data[index - 1 + i];
}
result[result.length - 1] = data[0];
return result;
}
}