Solved

using if in a program like the following example.

Posted on 2004-09-03
2
190 Views
Last Modified: 2010-03-31
System.out.println("\nThere were " + iArgumentCount + " command line " +
((iArgumentCount != 1)? "arguments":"argument") + ".");

This line in an program we are trying to disect (for school). Uses a ? and what looks like an if statement. Can you help explain this to me?

Thank You.

Steve
0
Comment
Question by:spoindex
  • 2
2 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11978299
Its a ternary statement.

Same as:

String args = null;
if (iArgumentCount != 1)
{
   args = "arguments";
}
else
{
   args = "argument";
}
System.out.println("\nThere were " + iArgumentCount + " command line " + args + ".");
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 11978302
a = b ? c : d; is shorthand for if ( b ) a = c; else a = d;
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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 …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

707 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

13 Experts available now in Live!

Get 1:1 Help Now