snowy0
asked on
args not working in if statement
I want to check when the user has entered in a question mark (or "/?" or "-?") as an argument.
This is my code:
if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {
System.out.println("help stuff")
}
I passed "/?" as an argument and nothing happened. I added some debugging code:
System.out.println(args[0] );
if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {
System.out.println("help stuff")
} else {
System.out.println("this text shouldnt be printed");
}
Once again I pass "/?" as an argument and get back:
/?
this text shouldnt be printed
Please help me.
Thanks in advance.
This is my code:
if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {
System.out.println("help stuff")
}
I passed "/?" as an argument and nothing happened. I added some debugging code:
System.out.println(args[0]
if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {
System.out.println("help stuff")
} else {
System.out.println("this text shouldnt be printed");
}
Once again I pass "/?" as an argument and get back:
/?
this text shouldnt be printed
Please help me.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
You could also do
if (args[0].matches("[/\\-]*\ \?"))
You could also do
if (args[0].matches("[/\\-]*\
should be
if ("//?".equals(args[0] ..........................