This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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=?
 
Similar Threads
Question on language Fundamentels..
Please Explain
Prime numbers
operator presedence
Rule Round Up #30 - What?? for loop declarations