unfamiliar syntax
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.
kimbokasteniv
Junior Poster in Training
50 posts since Nov 2006
Reputation Points: 13
Solved Threads: 4
^ 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.
if(condition)
foo();
else
bar();
// can also be done as:
condition ? foo() : bar();
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
Thanks; I should be able to find any other information with what you have given me.
kimbokasteniv
Junior Poster in Training
50 posts since Nov 2006
Reputation Points: 13
Solved Threads: 4