A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Introducing JavaFX 8 Programming
this week in the
PLease ignore previous post -Ternary operator
Joined: Aug 20, 2008
Aug 20, 2008 22:53:00
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?
Joined: Mar 22, 2005
Aug 20, 2008 23:35:00
The "a ? b : c" construct is an expression, not a statement, and can't be used where a statement is expected. Try
System.out.println( i%2==0 ? "Even" : "Odd" );
Jesper de Jong
Joined: Aug 16, 2005
Aug 21, 2008 01:37:00
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 8 API documentation
Joined: Oct 13, 2005
Aug 21, 2008 04:53:00
Note: more details in
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
Listing even and odd numbers
Syntax error for ternary operator
"assert i%2==0 : i--;"question required
Where to find ans for mock test by Valentinn Cretazz
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015