On Jul 12, 9:53 am, Dan <[email protected]> wrote: > Hello! I am having trouble figuring out how to access just the Array > [odd numbers]. This should be where the ages are located. > > public class testtwo { > > public static void main(String[] args) { > > Task: /Enter 3 to six names and ages on the command line : Name Age > /Next/: Separate names from ages. Ages should be odd numbered args > /How: Do I / make 'for loop' that just gets the odd number args[1], [3] > /Help: /for(int counter = 0; counter < args.length; counter++){/ > I just can't figure out how to 'count' odd numbers in array to get > the following: > > int int1 = Integer.parseInt(args[1]); > int int2 = Integer.parseInt(args[3]); > int int3 = Integer.parseInt(args[5]); > int averageResult = (int1 + int2 + int3+ int n)/N; > > System.out.println("Result of average age = " + averageResult); > } Not very sure if this will work, have not tested it myself: for(int counter=0; counter < args.length; counter ++){ if(counter % 2 != 0){ // Odd. } } > } > Any help or referral to articles is appreciated. I hope this is clear.
--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
