Could you not use a while loop with an if statement in it?

On Mon, Mar 2, 2009 at 5:19 AM, Thomas <[email protected]> wrote:

>
> Hello, I have problem executing the program like it is supposed to. I
> quote the description below:
>
> "4. (For your own exercise) Modify JavaArray.java as following, build
> and run the program.
>
>    * 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."
>
> My program looks like this:
>
> public class JavaArray {
>
>    /** Creates a new instance of JavaArray */
>    public JavaArray() {
>    }
>
>    /**
>     * @param args the command line arguments
>     */
>    public static void main(String[] args) {
>
>        // Declare and create int array whose size is 10
>        int[] ages = {100,101,102,103,104,105,106,107,108,109}; //new
> int[10];
>
>        // a value of 100 is assigned to the first entry of the array
>        for (int i : ages){
>
>        // Display the value of each entry in the array
>     //   for( i=0; i<ages.length; i++ ){
>            System.out.print(" " + i);
> //        }
>    }
>    }
> }
>
> It works OK, but how can I rewrite it to make use of both of the for
> loops? Thanks
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to