This week's book giveaway is in the OCAJP 8 forum.We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!

# 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=?