Can you use a for loop and increase the index by two to fetch only the
even number?
Example: for (int i=1; i < args.length; i = i+2){... args[i] ... } //
Since i starts from 0, thus the second, fourth, sixth parameters are
indexed with 1, 3, 5 etc.
Hope this help,
Patrick
On Mon, 2009-02-09 at 22:24 +0000, Brian Martin wrote:
> Hi,
>
> I have completed the homework for the Command Line Arguments topic but
> have a question before I submit my homework as I think there may be an
> easier way of doing it.
>
>
>
> When calculating the average age we need to ignore every second
> parameter (first parameter, third parameter, fifth parameter, etc) as
> these are the names of the family members.
>
> To ignore the names I have included a try and catch error handling so
> when I convert to a number the names go to the catch error handler
> where the catch code does nothing so the names are ignored. This seems
> to work ok.
>
>
>
> My question is if anybody has a simpler solution to ignore the names
> and calculate only the ages?
>
>
>
> Many thanks,
>
> Brian Martin
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---