集册 Java实例教程 声明,分配和分配值给数组

声明,分配和分配值给数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

566
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
声明,分配和分配值给数组

class ArrayDemo {

    public static void main(String[] args) {

        // declares an array of integers// 来 自 n o w j a v a . c o m - 时  代  Java

        int[] anArray;


        // allocates memory for 10 integers

        anArray = new int[10];


        // initialize first element

        anArray[0] = 100;

        // initialize second element

        anArray[1] = 200;

        // and so forth//NowJava.com - 时代Java 提供

        anArray[2] = 300;

        anArray[3] = 400;

        anArray[4] = 500;

        anArray[5] = 600;

        anArray[6] = 700;

        anArray[7] = 800;

        anArray[8] = 900;

        anArray[9] = 1000;


        System.out.println("Element at index 0: " + anArray[0]);

        System.out.println("Element at index 1: " + anArray[1]);

        System.out.println("Element at index 2: " + anArray[2]);

        System.out.println("Element at index 3: " + anArray[3]);

        System.out.println("Element at index 4: " + anArray[4]);

        System.out.println("Element at index 5: " + anArray[5]);

        System.out.println("Element at index 6: " + anArray[6]);

        System.out.println("Element at index 7: " + anArray[7]);

        System.out.println("Element at index 8: " + anArray[8]);

        System.out.println("Element at index 9: " + anArray[9]);

    }

}


展开阅读全文