package 专题练习; public class Copy_each_element_of_the_array { public static void main(String[] args) { //需求:复制数组中的每一个元素 //第一种方法 int[] array = new int[]{1,2,3,4,5}; int[] array1 = new int[5]; array1 = copyarray1(array); read_array(array1); } public static int[] copyarray1(int[] array){ int[] new_array = new int[5]; for (int i = 0; i < array.length; i++) { new_array[i] = array[i]; } return new_array; } public static void read_array(int[] data){ for (int i = 0; i < data.length; i++) { System.out.print(data[i] + " "); } } }
java专项练习(复制数组元素)
最新推荐文章于 2024-11-04 22:26:34 发布