The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Shift operator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Shift operator" Watch "Shift operator" New topic
Author

Shift operator

satishind Reddy
Ranch Hand

Joined: Oct 17, 2000
Posts: 33
i find this question from mock exam.
what is the output displayed by the following programe?
[CODE]
class Question{
public static void main(String args[]){
int n = 7;
n <<= 3;<br /> n = n & n+1 | n+2 ^ n+3 ;<br /> n >>= 2;
System.out.println(n);
}
}
can any one suggest fast way to calculate 'n' value.
I think this type of questions will take more time in exame. Is it possible to get this type questions in real exame.
Regards
Satish


Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Satishind,
First, I can't believe we will have a so complex question at the exam (I'm attending it on Thursday) because operators precedence are difficult to memorise properly. It is always advised to use parentheses to make a code more explicit to the reader.
Anyway, the easiest way to work out the results of binary operations is to express the result in binary form.

Please tell me if this is still unclear.
Regards,
Beno�t

[This message has been edited by Beno�t d'Oncieu (edited October 31, 2000).]
 
IntelliJ Java IDE
 
subject: Shift operator
 
Threads others viewed
Sun�s Questionary in SCJP 1.4
Exame Time ???
Are We doing wrong (IBM free Vouchers)
Do any one Know About XML dumps
Are there fill in the blank questions on the SCWCD 1.4 exam?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture