Solved

args not working in if statement

Posted on 2006-10-30
3
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jsp insert to database example 2 89
Is there a simpler dropbox system? 10 53
Html split(text) 2 48
Java regex 5 21
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.
Suggested Courses

732 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