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

Operators

harish shankarnarayan
Ranch Hand

Joined: Sep 12, 2005
Posts: 158
class EBH012 {
public static void main (String[] args) {
byte x = 3, y = 5;
//1 System.out.print((-x == ~x + 1)+","+(-y == ~y + 1));
}}

ans is True true how???
can any one explain bit by bit wat happens


Harish<br />SCJP 1.4 (85%)
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 171
Actually the highest precedence operators -,~ are evaluated first
so ~3 is -4, and ~5 is -6.
Then next highest priority operator + is evaluated,
so lefthand value will be -3 which is equal to right hand operand.
The result will be true,true.


Kiran Kumar.
harish shankarnarayan
Ranch Hand

Joined: Sep 12, 2005
Posts: 158
so ~3 is -4, and ~5 is -6.


can anyone explain how ~3 is -4 bit by bit
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Operators
 
Similar Threads
Parentheses in Expression
Swapping Values
Another IBM mock Exam Question
SCJP Brainteaser (9)
KB Question pg 314