File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes int i =2147483647 //(Max_Value);int j=i*2; j=? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int i =2147483647 //(Max_Value);int j=i*2; j=?" Watch "int i =2147483647 //(Max_Value);int j=i*2; j=?" New topic
Author

int i =2147483647 //(Max_Value);int j=i*2; j=?

sam huang
Greenhorn

Joined: Dec 31, 2002
Posts: 28
The result is -2.
Why?
[ January 04, 2003: Message edited by: sam huang ]

SCJP,SCWCD,SCBCD,MCSE
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
In binary,
i = 0111 1111 1111 1111 1111 1111 1111 1111 (you can verify, this add up to 2147483647)
j = i * 2
= 1111 1111 1111 1111 1111 1111 1111 1110
First bite is 1, so j is negative.
| j | = 0000 0000 0000 0000 0000 0000 0000 0010
so j = -2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int i =2147483647 //(Max_Value);int j=i*2; j=?