public class Test{
public static void main(String[] args) {
String array[] = {"A", "B", "C", "D", "E", "F","A"};
printArray(array);
}
public static void printArray(String[] array){
//新建一个字符串数组
String[] copyarray = new String[array.length];
//把传入的数组复制给新建的数组,变更时只变更新建数组的元素,原数组保持不变
System.arraycopy(array,0,copyarray,0,array.length);
int start = 1;//前角标,因第一个字符不变,从第二个开始(角标从0开始)
int end = copyarray.length-2;//后角标,因最后位置的字符不变,所以更换到倒数第二个
//遍历新建数组
for (int i = 0; i < copyarray.length-1; i++) {
//如果前角标和后角标一样,则只改变角标
if(start==end){
end--;
start++;
continue;
}
//遍历数组,打印数组元素
for (int j = 0; j < copyarray.length; j++) {
System.out.print(copyarray[j]);
}
//换行
System.out.println();
//变更新建数组的元素
copyarray[end] = array[start];
//变更角标
end--;
start++;
}
}
}