• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Confused with the output

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

public class TestClass7
{
public static void main(String[] args) throws Exception
{
System.out.println(Integer.MIN_VALUE);
int a = Integer.MIN_VALUE;
int b = -a;
System.out.println( a+ " "+b);
}
}


The output is -2147483648 -2147483648.Please explain why the output is not
-2147483648 2147483648.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java stores integers in two's complement format. The range for a 32-bit integer is -2^31 (-2147483648) to 2^31 - 1 (2147483647). The number 2147483648 (which is 2^31) does not fit in an integer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic