This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt #2

 
AJAY JOSE PAUL
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
AJAY JOSE PAUL
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic