On Jan 5, 4:01 pm, Rene Olgers <ollie1...@gmail.com> wrote: > Hi Michele, > > thank you for your email. > In this case I try to assign a value of 100 to the first entry, 101 to > the second and etc. > Instead of assigning all values by hand I want to use a loop. > > Could you please assist? Well, that is the homework, so I will not give the solution, but: ages[j] = j; is the same as: ages[j] = j + 0; Is not it? So, you have the solution now.
Michèle Garoche > > Thanks, > > René > > On 4 jan, 07:17, Michèle Garoche <migat...@gmail.com> wrote: > > > > > On Jan 4, 12:25 am, Rene Olgers <ollie1...@gmail.com> wrote: > > > > public class ArrayTest { > > > > /** > > > * @param args the command line arguments > > > */ > > > public static void main(String[] args) { > > > // Declare and create new int array whose size is 10 > > > int[] ages = new int[10]; > > > int j = 100; > > > int count = 0; > > > > // Display the values of each entry in the array > > > while (count<ages.length){ > > > System.out.println(ages[j] ); > > > count++; > > > j++; > > > > } > > > } > > > > } > > > To complete what others have already said, it would be probably better > > to fill your array with meaningful numbers, unless you insist in > > having 0 (the default value when none is supplied) in all elements, as > > you have just declared the array (that is allocated memory for it and > > initialize all elements to default value), but you have not > > initialized it (giving each element a value). > > > In this case, just add at the top of the loop: > > ages[j] = j; > > to get 0,1, ... 9 for example > > > Michèle Garoche -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en