This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic

PLease ignore previous post -Ternary operator

 
rachel biji
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
What is wrong with this code:


(i%2==0)?System.out.println("Even"):System.out.println("Odd");
The complilation error being "Not a statement"

I also tried
(i%2==0?(System.out.println("Even");)System.out.println("odd");));
though it didnt look right..

Can you please give me an explanation?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
The "a ? b : c" construct is an expression, not a statement, and can't be used where a statement is expected. Try
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47288
52
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic