|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Problem with tertiary conditional operator ?:
Here's my code:
[/COLOR] public class Hello { [/COLOR] public static void main(String[] args) { //if x >= 5 leave it alone, if it's < 5 then negate it. int x = 3; (x >= 5) ? 1*x : -1*x; }//end of main() method }//end of Hello class Here's the error message when I try to compile: C:\DATA\Hello.java:7: not a statement (x >= 5) ? 1*x : -1*x; ^ 1 error Tool completed with exit code 1 The ^ is under the ?. [COLOR=blue]Any ideas on what I'm missing? Thanks for your help. |
|
#2
|
||||
|
||||
|
I imagine you need to assign this expression to a value. Currently, it's as if you're just printing, for example:
Code:
6; |
|
#3
|
|||
|
|||
|
Assignment
Assign the result of the tertiary expression to an int vairable.
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Problem with tertiary conditional operator ?: |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|