---------- Forwarded message ----------
From: Vishal <[email protected]>
Date: Sat, Mar 27, 2010 at 1:56 AM
Subject: Re: [java programming] homework 1038 command line arguments help
To: [email protected]


/**
 * @author Tosh
 */
public class CommandLineArguments {

    public static void main(String[] args) {
    // Check if a command line argument exists
        if((args.length <6)||(args.length>12))
           {
            System.out.println("Please enter 3 to 6 name age pairs.");
            System.exit(0);
           }
        else
           {
    //create variables
        int agetotal = 0;
        int ageaverage = 0;
        int entries = args.length / 2;

    //loop it to add them up
        for(int i = 0; i<args.length; i++){
        i++;  //increment again to get the odd array numbers
        agetotal = Integer.parseInt(args[i]) + agetotal;
        System.out.println("current age total is: " + agetotal);
        }

    //divide to get the average and display it
        ageaverage = agetotal/entries;
        System.out.println("The average age is " + ageaverage);
      }
    }
}

I hope that should solve your problem try it out.


On Fri, Mar 26, 2010 at 11:58 PM, Tosh <[email protected]> wrote:

> I've been going over this for a while. It worked once with 4 entries. Then
> it stopped working but I did not make any changes that I was aware of. The
> initial test for arguments works. if it is not 3 - 6 pairs entered it will
> exit and complain.
>
> For some reason if you enter 3 - 6 pairs it runs successfully but never
> outputs the end result. I put code in the loop to see if it would output
> that and it does not seem to be getting that far either.
>
> Nothing highlights in red in netbeans so there must be some logic error
> that I don't understand.
>
>
>
>
> /**
>  * @author Tosh
>  */
> public class CommandLineArguments {
>
>     public static void main(String[] args) {
>     // Check if a command line argument exists
>         if((args.length <6)||(args.length>12))
>             System.out.println("Please enter 3 to 6 name age pairs.");
>             System.exit(0);
>
>     //create variables
>         int agetotal = 0;
>         int ageaverage = 0;
>         int entries = args.length / 2;
>
>     //loop it to add them up
>         for(int i = 0; i<args.length; i++){
>         i++;  //increment again to get the odd array numbers
>         agetotal = Integer.parseInt(args[i]) + agetotal;
>         System.out.println("current age total is: " + agetotal);
>         }
>
>     //divide to get the average and display it
>         ageaverage = agetotal/entries;
>         System.out.println("The average age is " + ageaverage);
>     }
> }
>
> --
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]<javaprogrammingwithpassion%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>
> To unsubscribe from this group, send email to javaprogrammingwithpassion+
> unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> ME" as the subject.
>



-- 
Thank You,
Vishal.



-- 
Thank You,
Vishal.

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

To unsubscribe from this group, send email to 
javaprogrammingwithpassion+unsubscribegooglegroups.com or reply to this email 
with the words "REMOVE ME" as the subject.

Reply via email to