Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Passing in more than one flag

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Passing in more than one flag

    If I were to take in more than one flag from the command line, such as "java myProgram -a -b -c Hey" and each flag prompted an alteration of the word "Hey", how would I go about doing that? I tried using if-else statements but was only able to get one flag recognized at a time.

    If this thread should be moved, feel free to do so, I wasn't sure what forum to put it under.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Passing in more than one flag

    Loop through all the arguments passed in.

    for (int i = 0; i < args.length; i++)
    {
         // where to parse what each flag does
    }

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Passing in more than one flag

    Would I use if-else statements for each flag's situation within the loop? Would I even use if-else statements at all?

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Passing in more than one flag

    The loop that helloWorld922 posted above is showing u how to get all the parameters from the command line. If you want to specify some action for some specific parameter that user will enter then you can use if statements to alter each one. You can even use a switch statement. Just play a bit with your code and i'm sure that you will understand it better. And once you did you will not forget, something like riding a bicycle

Similar Threads

  1. Passing Information between classes
    By SKhoujinian91 in forum Object Oriented Programming
    Replies: 4
    Last Post: December 8th, 2009, 03:40 PM
  2. what if flag?
    By chronoz13 in forum Java Theory & Questions
    Replies: 8
    Last Post: November 8th, 2009, 12:44 AM
  3. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 04:31 AM