Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes the ? and : operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the ? and : operators" Watch "the ? and : operators" New topic

the ? and : operators

Gaia Nathan
Ranch Hand

Joined: Aug 01, 2001
Posts: 62
Can someone tell me what the ? and : operators do?
I can't find a reference to them.
Sunetra Saha
Ranch Hand

Joined: Feb 25, 2001
Posts: 77
they make up a consolidated if-else syntax.
You can write the following if statement
{ statementA;
}else statementB;
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Actually, the ? : is called the Conditional Operator. Some code to illustrate what Sunetra wrote:

Hope this helps!
Gaia Nathan
Ranch Hand

Joined: Aug 01, 2001
Posts: 62
Thanks Sunetra, Kaspar. Both your replies made it very clear for me.
wood burning stoves
subject: the ? and : operators
jQuery in Action, 3rd edition