Home / Programs / An array example in java
🚀 Programming Example

An array example in java

👁 5,496 Views
💻 Practical Program
📘 Step Learning
Important of an array example

💻 Program Code

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]);
       }

    }
}
                        

🖥 Program 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.
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.