initialization of Array:
* assigning values to an array
syntax:
datatype arrayname[]={val1,val2,...};
example:
int x[]={4,5,6,3,4,1};
begin index = 0
end index= 5
How to find length of an array?
* length property of an array will return length of an
array
length = number of elements
syntax:
arrayname.length
ex:
int x[]=new int[6];// default value 0
System.out.println(x.length);
How to count without using length property?
int x[]={1,4,2,3,5,6,7};
int count=0;
for(int i=0;i<7;i++){
count++;
}
System.out.println(count);
How to access each element of array?
* arrayname[index] to access each invdividual element
ex:
int x[]={4,2,4,6,5,4};
//print element at index 4
System.out.println(x[4]);
//print element at location 4
System.out.println(x[3]);