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]);
}
}
10
20
30
40
50
Press any key to continue . . .
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.
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.