Solved

args not working in if statement

Posted on 2006-10-30
3
265 Views
Last Modified: 2012-05-05
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
Comment
Question by:snowy0
  • 3
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17838097
>>if (args[0] == "/?" || args[0] == "-?" || args[0] == "?") {


should be


if ("//?".equals(args[0] ....................................................
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 17838099
Sorry

if ("/?".equals(args[0] ....................................................
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17840395
:-)

You could also do

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 86
array11 challenge 16 51
mapAB Challlenge 35 85
reasons why a "inside Menu" would not appear for a web server 6 43
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now