• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

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.

0
snowy0
Asked:
snowy0
  • 3
1 Solution
 
CEHJCommented:
>>if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {


should be


if ("//?".equals(args[0] ....................................................
0
 
CEHJCommented:
Sorry

if ("/?".equals(args[0] ....................................................
0
 
CEHJCommented:
:-)

You could also do

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now