Arrays:
- An Array is a collection of similar type of elements
- The advantage of array is we can represent multiple values under the same name
- once we create an array there is no chance of increasing\decreasing the size of an array
- we can resolve this problem using collections
Program on Array
class ArrayDemo{
public static void main(String args[]){
int a[]=new int[6];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
a[5]=60;
//printing array
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}}
output:
10
20
70
40
50
60

No comments:
Post a Comment