James,
Here is how I did it. (Not the only way by any means) The code is
bold is how I initialize the values in the array before the loop that prints
them.
// Declare and create int array whose size is 10
int[] ages = new int[10];
*int initcounter = 100;*
* for( int i=0; i<ages.length; i++ ){
initcounter ++;
ages[i] = initcounter;
}*
// Display the value of each entry in the array
for( int i=0; i<ages.length; i++ ){
System.out.print( ages[i] + " " );
}
}
On Thu, Jan 22, 2009 at 7:53 AM, james livsey <[email protected]>wrote:
> Hi,
>
> I have a quick question - on one of the exercises of the array lab it asks;
>
>
> - Just before the for loop that prints out the value of each entry of
> the ages[] array, create another for loop in which a value of 100 is
> assigned to the first entry of the array, ages[0], 101 to the next entry of
> the array, ages[1], and so on.
>
>
> the way i achieved this was;
>
> for(int j = 0; j < ages.length; j++){
> ages[j] = j+100;
> System.out.println(ages[j]);
> }
>
>
> but im pretty sure thats not the way to do it.
>
> can anyone tell me the correct way?
>
> thanks
>
> James
>
> >
>
--
Regards,
Mike Towery
VP of Operations
KnightWorks Consulting
www.knworks.com
[email protected]
Office (214)764-6328
Cell No: (214) 563-6358
Pager No: (877) 317-5063
Fax No: (214) 291-5979
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---