Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old January 23rd, 2004, 09:23 PM
singhnx singhnx is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Chicago, IL
Posts: 9 singhnx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 26th, 2004, 07:20 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
I imagine you need to assign this expression to a value. Currently, it's as if you're just printing, for example:

Code:
6;

Reply With Quote
  #3  
Old May 30th, 2008, 03:57 PM
TopSecret TopSecret is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 TopSecret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 11 sec
Reputation Power: 0
Assignment

Assign the result of the tertiary expression to an int vairable.





Quote:
Originally Posted by singhnx
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Problem with tertiary conditional operator ?:


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway