Hi John,
Here is the exact exercise:
"Create a program that will print every other argument given on the command line. If the program was executed with the following on the command line:
java ArgumentSkipper one two three a b c d
the program would print:
one
three
b
d
"
Here is the solution from the book:
public class ArgumentSkipper {
public static void main(
String args[]) {
int count = args.length;
// Iterate over the arguments skipping two places
// forward between each step.
for (int i=0; i < count; i+=2) {<br /> System.out.println(args[i]);<br /> }<br /> }<br /> }<br /> When I compiled and ran it on my machine. I got this result:<br /> > java ArgumentSkipper one two three a b c d
one
three
When I changed the for loop to "for (int i=0; i < count; i++)", I got:
one
two
three
a
Then I suspected that my machine (setup) restricts my program from receiving more than 4 arguments.
I really appreciate your help.
Thanks,
Doanh