Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using if in a program like the following example.

Posted on 2004-09-03
2
Medium Priority
?
197 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
[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
  • 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 500 total points
ID: 11978302
a = b ? c : d; is shorthand for if ( b ) a = c; else a = d;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

718 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