Home / Programs / Example of single dimensional java array
🚀 Programming Example

Example of single dimensional java array

👁 1,293 Views
💻 Practical Program
📘 Step Learning
Example of single dimensional java array

💻 Program Code

public class ArrayExample {

   public static void main(String args[]){

   int a[]=new int[5];//declaration and instantiation
   a[0]=10;//initialization index 0
   a[1]=20;//initialization index 1
   a[2]=30;//initialization index 2
   a[3]=40;//initialization index 3
   a[4]=50;//initialization index 4

   //printing array
   for(int i = 0; i < a.length; i++)//length is the property of array
   System.out.println(a[i]);

   }
}
                        

🖥 Program Output

10
20
30
40
50
Press any key to continue . . .
                            

📘 Explanation

The above program is an example of single dimensional java array
📚 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.