package com.mohuanan.exercise;
public class Exercise {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 8}; //格式化快捷键 CTRL 加 Alt 加 L键
// F1截图 F3贴图
//调用 copyOfRange
int[] ints = copyOfRange(arr, 3, 7);
for (int i = 0; i < ints.length; i++) {
System.out.print(ints[i]+ " ");
}
System.out.println();
}
public static int[] copyOfRange(int[] arr,int from,int to){
//动态定义一个数组
int[] newArr = new int[to-from];
for (int i = from; i < to; i++) {
newArr[i-from] = arr[i];
}
return newArr;
}
}
运行结果: