Sample Array program

example

The following sample array program creates an array of integers , put some values and prints to the standard output

class ArrayDemo {
    public static void main(String[] args) {
        // declares an array of integers
        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
        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]);
    }
} 

The output from this program is:

Element at index 0: 100
Element at index 1: 200
Element at index 2: 300
Element at index 3: 400
Element at index 4: 500
Element at index 5: 600
Element at index 6: 700
Element at index 7: 800
Element at index 8: 900
Element at index 9: 1000

4 thoughts on “Sample Array program

  1. Oh my goodness! a tremendous article dude. Thank you However I am experiencing concern with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting similar rss drawback? Anyone who is aware of kindly respond. Thnkx

  2. I like the helpful info you provide in your articles. I will bookmark your weblog and check again here regularly. I’m quite sure I’ll learn plenty of new stuff right here! Best of luck for the next!

  3. I precisely wanted to thank you so much once again. I’m not certain what I might have created without these tips and hints shared by you directly on that area. Previously it was a challenging problem in my circumstances, but discovering your specialised form you treated the issue forced me to leap with happiness. I am happier for the assistance and in addition sincerely hope you recognize what a great job you have been undertaking teaching many people via a site. I know that you have never got to know all of us.

  4. I really believe this really is amongst the this sort of lot
    vital information for me. And i’m glad reading your article.
    However wanna observation on few normal things, The site style is perfect,
    the articles is really excellent : D. Excellent process, cheers

Leave a Reply

Your email address will not be published. Required fields are marked *