public class Test {
    public static void main(String[] args)
    {
        //静态初始化
        int[] gather;
        gather = new int[] {1,2,3,4,5,6,7};
        Object[] gather2;
        System.out.println(gather[6]);
        gather2 = new String [] {"Hello","World"};
        System.out.println(gather2[1]);
        //动态初始化
        var we = new String[] {"J","O","E","Y"};
        System.out.println(we[1]);
        for (String wes : we) {
            System.out.println(wes);
        }
        Object[] animals = new String[9];
        animals[1] = "Pig";
        animals[2] = "Sheep";
        animals[3] = "Cow";
        for ( var i = 1; i < animals.length; i++)
        {
            System.out.println(animals[i]);
        }
    }
}
最后修改:2022 年 09 月 17 日
如果觉得我的文章对你有用,只需评论或转发支持,谢绝投喂!