aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can anyone pls explain about the output of this prog. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Can anyone pls explain about the output of this prog." Watch "Can anyone pls explain about the output of this prog." New topic
Author

Can anyone pls explain about the output of this prog.

Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 101
Pls look at the following code. Can anyone pls explain me the output.


The output is : -2147483648 -2147483648
Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115
here b should show the value '2147483648' but the maximum positive number is '2147483647'.
Actually these values lie in circular form so the desired result is 2147483648 i.e. '2147483647+1' so when we add 1 to 2147483647, the value becomes -2147483648.

try this program



output:
-2147483648
2147483647


i hope you got it.
Chetan Raju
Ranch Hand

Joined: Aug 02, 2006
Posts: 109
There is no concept of overflow error/exception in integer arithmetic. When you negate the largest negative number, you get a positive number which is out of range of integer. So it wraps to the smallest no which is again the integer minimum value.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Can anyone pls explain about the output of this prog.
 
Similar Threads
Simple code strange output aleast for me
negation of integers
Negation of Integers
Casting Difference of Float.POSITIVE_INFINITY
Confused with the output