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 Doubt #2 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 "Doubt #2" Watch "Doubt #2" New topic
Author

Doubt #2

AJAY JOSE PAUL
Greenhorn

Joined: Nov 11, 2006
Posts: 4
What happens when you try to compile and run the following class...
public class TestClass{
public static void main(String[] args) throws Exception{
int a = Integer.MIN_VALUE;
int b = -a;
System.out.println( a+ " "+b);
}
}


Output?

Your comments please... with explanations.


I am not a player, I am the 'GAME'
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What happened when you compiled and ran the code? What do you not understand about the output?
[ November 18, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
AJAY JOSE PAUL
Greenhorn

Joined: Nov 11, 2006
Posts: 4
What happened when you compiled and ran the code? What do you not understand about the output?


Well... the output did not make sense to me.
The output is -2147483648 -2147483648

Any idea?
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Printing Integer.MIN_VALUE will give you -2147483648 and again negating this number will give +2147483648 (out of the range from Integer.MAX_VALUE i.e. equals to Integer.MAX_VALUE+1).Doing the 2's compliment airithmetic to fit this number in 32 bit scheme ,you will get the answer as -2147483648.


~Sanjeev Singh<br />SCJP 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt #2