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.
Re: Passing in more than one flag
Loop through all the arguments passed in.
Code :
for (int i = 0; i < args.length; i++)
{
// where to parse what each flag does
}
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?
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 :P