package com.sxt.arraytest1; import java.util.Arrays; /* * 一维数组 */ public class ArrayTest2 { public static void main(String[] args) { //动态初始化 int[] arr1 = new int[5]; System.out.println(Arrays.toString(arr1));//初始化为0:[0, 0, 0, 0, 0] String[] s = new String[3];//初始化为null:[null, null, null] System.out.println(Arrays.toString(s)); //静态初始化1 int[] arr2 = {1,3,4,5,7}; System.out.println(Arrays.toString(arr2)); //静态初始化2 int[] arr3 = new int[]{2,3,5,6,7}; System.out.println(Arrays.toString(arr3)); //一维数组的遍历方式一:可以操作下标 for(int i=0; i<arr3.length; i++){ System.out.print(arr3[i]+" "); } System.out.println(); //一维数组的遍历方式二:增强for循环 简单 for(int num: arr3){ System.out.print(num + " "); } } }