I'm trying to figure out what is wrong with this program.
The line:
"int aveAge = (aveAge/(args.length/2);"
is giving the error that "variable aveAge might not have been initialized.
The 29th line, that begins with:
"for(int counter=3; counter < args.length; counter= counter+2){"
is giving the error that "array req but int found."
The next line states "Cannot find symbol class String."
Cheers.
Rob B.
public class OwnCommandLineArguments {
public static void main(String[] args) {
System.out.println("Please input a name followed by an age. " +
"Do this at for at least three names; six names " +
"max, all on the same line.");
// Check if a command line argument exists
if(args.length == 0)
System.exit(0);
if ((args.length<6)||(args.length>12)){
System.out.println("Please input a name followed by an age. Do " +
"this at for at least three names; six names max, all on " +
"the same line.");
System.exit(0);
}
// Calculate the average age
for(int counter=2; counter<args.length; counter=counter+2){
int aveAge = Integer.parseInt(args[counter] + args[counter-2]);
}
int aveAge = (aveAge/(args.length/2);
System.out.println("The average age is " + aveAge);
// Calculate the longest name
for(int counter=3; counter < args.length; counter= counter+2){
if (args.length[counter]) > (args.length[counter-2]){
string maxName=args[counter];
else
string maxName=args[counter-2];
System.out.println("The longest name is:" + maxName);
}
}
}
}
--
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.