How do you use the array.length feature to determine what is in an array?

From ggc

Jump to: navigation, search

The array.length field tells how many elements are in the array. This can be used to tell what is in the array. For example, here is some code that declares and initializes an array then prints out what is in the array.

int[] nums=new int[5];
nums[0]=4;
nums[1]=42;
nums[2]=14;
nums[3]=34;
nums[4]=45;
for(int x=0; x<nums.length; x++)
{
   System.out.println("element "+x+" is "+nums[x]);
}

Does this help answer your question?





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter