Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

Why is integar.min_value and integar.max_value equal to 1 in java?

Asked by Anisha Dalal Oct 13, 2022 1.4K views 1 answer
Share

About this question

If you run the statement:


System .out.println( (Integer.MIN_VALUE)-(Integer .MAX_VALUE ));
In java it returns 1 as the answer. Is this because Java just considers those values as 32bit integers without considering their sign?
Integer.MIN_VALUE = 10000000000000000000000000000000
Integer.MAX_VALUE = 1111111111111111111111111111111
I get why -MIN.VALUE == MIN_VALUE returns true. And how MAX_VALUE+1 causes the Integer overflow and we get the result. But I cannot clearly wrap my head around how subtraction is working.

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.