Hi,
public class OwnCommandLineArguments {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] Integerarray = new int[6];
int count=0;
int counter=0;
int Integerarraylength=0;
int sum=0;
int average=0;
System.out.println(" Calculating the average age of all Family
Members :");
System.out.println(" Please enter the Argumenst in the Following
Way...Name Age");
//Asking the user to Enter 5 command line arguments
if(args.length !=5){
System.out.println(" Invalid number of Arguments...Please enter 5
argumenst");
}
for(int i= 0;i < args.length; i++){
System.out.println(args[i]);
}
for(count =0;count < args.length;count=count+2){
Integerarray[counter]= Integer.parseInt(args[count+1]);
System.out.println(Integerarray[counter]);
counter++;
//count= count+2;
}
Integerarraylength = counter;
System.out.println(Integerarraylength);
for(int i=0;i<Integerarraylength;i++){
sum = sum +Integerarray[i];
System.out.println(sum);
}
System.out.println(" Sum is "+ sum);
average = sum/Integerarraylength;
System.out.println(" Average is "+ average);
}
}
This is what i have written and pass in Arguments as
Vinith 25 Ankur 25 Jay
The output i get is Calculating the average age of all Family Members :
Please enter the Argumenst in the Following Way...Name Age
Vinith
25
Ankur
25
Jay
25
25
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at OwnCommandLineArguments.main(OwnCommandLineArguments.java:38)
Java Result: 1
Can u tell me what is the problem. I think the numbers do get stored in the
Integer array.Please advice
Thanks and Regards
Vinith
--
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