* ^ * wrote:
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.
 }
}
  

Or an even easier way to do this would be...

for (int count = 1; counter < args.length; count += 2) {
    // Processing code goes here
}

    }
Any help or referral to articles is appreciated. I hope this is clear.
    

  

No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.375 / Virus Database: 270.13.11/2232 - Release Date: 07/11/09 17:56:00


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