Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

using if in a program like the following example.

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
spoindex
Asked:
spoindex
  • 2
1 Solution
 
objectsCommented:
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
 
objectsCommented:
a = b ? c : d; is shorthand for if ( b ) a = c; else a = d;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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