| | |
unfamiliar syntax
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2006
Posts: 23
Reputation:
Solved Threads: 0
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:
If someone could atleast point me to a web page that explains those operators, I would much appreciate it.
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.
^ 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.
?: is the ternary operator, so named because it takes three parts (see example below). It's shorthand for an if-else clause.
Java Syntax (Toggle Plain Text)
if(condition) foo(); else bar(); // can also be done as: condition ? foo() : bar();
Last edited by Infarction; Feb 6th, 2007 at 7:10 pm.
![]() |
Similar Threads
- more syntax questions (Java)
- MySQL syntax error check for the right syntax to use near 'A (A) )' at line 1 (PHP)
- Parse error, syntax error, Forbids declaration (C++)
- Syntax for deleting specified file ( in C++) (C++)
- C++ Syntax (C++)
Other Threads in the Java Forum
- Previous Thread: swing program using ftp protocol
- Next Thread: What is wrong with my java program
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation binary blackberry block bluetooth character chat class classes client code compile component consumer database desktop developmenthelp eclipse error exception fractal freeze ftp game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaee javaprojects jmf jni jpanel julia lego linked linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number online page print printf problem program programming project properties recursion researchinmotion rotatetext rsa scanner screen server set singleton size sms sort sql string swing template textfields threads time title tree tutorial-sample update windows working






