Link to home
Start Free TrialLog in
Avatar of snowy0
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.

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {


should be


if ("//?".equals(args[0] ....................................................
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)

You could also do

if (args[0].matches("[/\\-]*\\?"))