• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Program can only receive up to 4 arguments???

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
I am a Java newbie. I compiled and ran a test program in my book, but did not get the same answer because my program can only receive up to 4 arguments. Example: java Guest 1 2 3 4 5 6 7 8 9. The program can only accept up to 1 2 3 4.
Is there something I missed during JDK 2 installation? I have JDK1.3 and Win98.
Thank you very much,
Doanh Nguyen
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know that the program could only receive 4 args? Did you get some error messages or some other indication? If you did receive some errors could you post them along with the code?
If you run into things that look strange you may want to go out to java.sun.com, become a member of the Java Developer Connection (JDC), and search their bug database to see if something is a known problem. You can also search the Java Ranch forums to see if there are any posts on the subject.
John
 
Doanh Nguyen
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried your program and it works perfectly.. There is no restriction as far as the number of arguments are concerned.
Kalidas.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The program is absolutely correct.There is no problem with the code U must get the same output.
 
Doanh Nguyen
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the cause for the restriction. It's like shooting myself in the foot: My JR.BAT file contains the argument limit: JAVA -classpath %javadir% %1 %2 %3 %4 %5, with %1 being the program name and the other four variables for the parameters.
Thanks for all your help.
Doanh
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doanh,
Thanks for posting the code. It usually helps troubleshoot a problem quicker. I didn't have time to check in today until now and am glad to see you have solved the problem on your own.
John
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic