Hi René, There are a couple of problems with your code. Firstly, you are referring to an element within your while loop that is at position 100 within the array. Your array has 10 items in it, which you specified when you created the array, so the index 100 is out of bounds.
Secondly, you don't really need the count variable unless you want to keep a count of the number of items in the array. But you initialized it to hold 10 ints already. Also, when you iterate over the array to display its elements, you can do something like this: while(j < ages.length){ print each element; increment the value of the index ( j ); } Before this line you should have initialized j to 0 (i.e. int j = 0;) In the body of the while loop, you can increment j, so that eventually the condition in the while loop will become false. (i.e. j will be > the length of the ages array). Hope this helps! Andre On Mon, Jan 3, 2011 at 6:25 PM, Rene Olgers <ollie1...@gmail.com> wrote: > Hi All, > > I try this code but I can't get it to work. > please help. > > GRTZ, > René > > 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 post to this group, send email to > javaprogrammingwithpassion@googlegroups.com > To unsubscribe from this group, send email to > javaprogrammingwithpassion+unsubscr...@googlegroups.com<javaprogrammingwithpassion%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/javaprogrammingwithpassion?hl=en -- 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