Go Back   Java Programming Forums > Java Standard Edition Programming Help > Loops & Control Statements


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-01-2010, 07:37 PM
Junior Member
 

Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
anon181 is on a distinguished road
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.



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 29-01-2010, 10:19 PM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,215
Thanks: 5
Thanked 258 Times in 234 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
Default Re: Passing in more than one flag

Loop through all the arguments passed in.

Java Code
for (int i = 0; i < args.length; i++)
{
     // where to parse what each flag does
}
__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
  #3 (permalink)  
Old 01-02-2010, 05:58 AM
Junior Member
 

Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
anon181 is on a distinguished road
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?
Reply With Quote
  #4 (permalink)  
Old 02-02-2010, 10:37 AM
Junior Member
 

Join Date: Feb 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
johniem is on a distinguished road
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Information between classes SKhoujinian91 Object Oriented Programming 4 08-12-2009 07:40 PM
what if flag? chronoz13 Java Theory & Questions 8 08-11-2009 04:44 AM
Passing objects as a constructor parameter derky Object Oriented Programming 2 27-10-2009 08:31 AM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 02:06 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.