This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes PLease ignore previous post -Ternary operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

PLease ignore previous post -Ternary operator

rachel biji

Joined: Aug 20, 2008
Posts: 4
What is wrong with this code:

The complilation error being "Not a statement"

I also tried
though it didnt look right..

Can you please give me an explanation?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41180
The "a ? b : c" construct is an expression, not a statement, and can't be used where a statement is expected. Try

Ping & DNS - my free Android networking tools app
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Note: You can edit your own posts by clicking the icon on the post - no need to start a completely new post if you made some mistake.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38087
Note: more details in this thread.

But we don't like two threads about the same question, I feel obliged to close one. I shall close this thread; please everybody continue any discussion on the other thread quoted above.
I agree. Here's the link:
subject: PLease ignore previous post -Ternary operator
Similar Threads
Listing even and odd numbers
Regarding assertion
"assert i%2==0 : i--;"question required
Ternary operator
Syntax error for ternary operator