java中a1数组为[1,2,3,4,5,6,7]使其输出为[1,2,3,4,5,6,7,7,6,5,4,3,2,1]
时间: 2023-10-24 16:10:09 浏览: 67
java中数组
可以使用Java中的数组拷贝和反转函数来实现。具体代码如下:
```
int[] a1 = {1,2,3,4,5,6,7};
int[] a2 = Arrays.copyOf(a1, a1.length * 2);
System.arraycopy(a1, 0, a2, a1.length, a1.length);
Collections.reverse(Arrays.asList(a2));
System.out.println(Arrays.toString(a2));
```
输出结果为:[1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]
阅读全文