Important of an array example

Java Programming Language / Array in java

5449

Program:

class ArrayDemo{
     public static void main(String args[]){
        int array[] = new int[7];
        for (int count=0;count<7;count++){
           array[count]=count+1;
       }
       
       for (int count=0;count<7;count++){
           System.out.println("array["+count+"] = "+array[count]);
       }

    }
}

Output:

array[0] = 1
array[1] = 2
array[2] = 3
array[3] = 4
array[4] = 5
array[5] = 6
array[6] = 7
Press any key to continue . . .

Explanation:

Save , Compile & Run the code. Observe the Output. If x is a reference to an array, x.length will give you the length of the array. Unlike C, Java checks the boundary of an array while accessing an element in it. Java will not allow the programmer to exceed its boundary.

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.