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

Example of single dimensional java array

👁 1,293 Views
💻 Practical Program
📘 Step by 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]);

   }
}

Output

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

Explanation

The above program is an example of single dimensional java array

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.