package day04;
public class ArrayDemo1 {
public static void main(String[] args){
// 数组的截取 截取的是12 6 43 2
// 0 1 2 3 4 5 6 7
// 截取的索引是2-6:要前不要后
int[] arr ={23,45,12,6,43,2,4,89};
// 定义截取范围
int start = 2;
int end = 6;
// 定义新数组 进行接收 截取片段 0 1 2 3
int[] newArr = new int[end - start];
// 将截取片段 添加到新数组中 0 - 3
// start + i 从2 - 5
for(int i = 0; i < newArr.length; i++){
newArr[i] = arr[start + i];
}
// 打印新数组的值
int j = 0;
while(j<newArr.length){
System.out.println(newArr[j] + " ");
j++;
}
}
}
数组的截取
最新推荐文章于 2024-06-14 14:08:37 发布