unfamiliar syntax

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2006
Posts: 23
Reputation: kimbokasteniv is an unknown quantity at this point 
Solved Threads: 0
kimbokasteniv kimbokasteniv is offline Offline
Newbie Poster

unfamiliar syntax

 
0
  #1
Feb 6th, 2007
I was going through the questions in my study guide for computer science, and I noticed a few blocks of code that contained syntax that I had never used before.

My first question is on the ^ operator.
What exactly does this do?

My second questions is on the use of : and ? in if and for statements.
What exactly do these operators do?

Here are the blocks of code that they are featured in:

int x= 2^3;

System.out.println((x<y)?((y<z)?z:y):
((x<z)?x:z));


If someone could atleast point me to a web page that explains those operators, I would much appreciate it.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: unfamiliar syntax

 
0
  #2
Feb 6th, 2007
^ is a bitwise XOR operator. It can only be used on primitive integer types.

?: is the ternary operator, so named because it takes three parts (see example below). It's shorthand for an if-else clause.
  1. if(condition)
  2. foo();
  3. else
  4. bar();
  5. // can also be done as:
  6. condition ? foo() : bar();
Last edited by Infarction; Feb 6th, 2007 at 7:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 23
Reputation: kimbokasteniv is an unknown quantity at this point 
Solved Threads: 0
kimbokasteniv kimbokasteniv is offline Offline
Newbie Poster

Re: unfamiliar syntax

 
0
  #3
Feb 6th, 2007
Thanks; I should be able to find any other information with what you have given me.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC