Author
PLease ignore previous post -Ternary operator
rachel biji
Greenhorn
Joined: Aug 20, 2008
Posts: 4
posted Aug 20, 2008 22:53:00
0
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
Marshal
Joined: Mar 22, 2005
Posts: 35440
posted Aug 20, 2008 23:35:00
0
The "a ? b : c" construct is an expression, not a statement, and can't be used where a statement is expected. Try
Android apps – ImageJ plugins – Java web charts
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12952
posted Aug 21, 2008 01:37:00
0
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
Sheriff
Joined: Oct 13, 2005
Posts: 32830
posted Aug 21, 2008 04:53:00
0
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.
subject: PLease ignore previous post -Ternary operator