首页 > 代码库 > Java一维数组

Java一维数组

//静态初始化数组        int[] array1 = new int[]{0,1,2,3,4};        //动态初始化数组        int[] array2 = new int[5];        System.out.println(array1);        for(int i=0;i<array1.length;i++){               System.out.println("array1:"+array1[i]);        }        for(int i=0;i<array2.length;i++){               System.out.println("array2:"+array2[i]);        }                 //数组的复制        int[] a = new int[]{23,43,54,26,94,34};        int[] b = new int[6];        for(int i=0;i<b.length;i++){            b[i]=a[i];        }        for(int i=0;i<b.length;i++){            System.out.print(b[i]+",");        }        System.out.print("\n");        //数组的反转        for(int i=0;i<a.length/2;i++){            int temp = a[i];            a[i]=a[a.length-1-i];            a[a.length-1-i]=temp;        }        for(int i=0;i<a.length;i++){            System.out.print(a[i]+",");        }

Java一维数组