-3

I tried to print the results, but unable to get the reason behind this.Anyhelp would be greatly appreciated.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
Gautam Tyagi
  • 140
  • 4
  • 16

1 Answers1

-1

I guess we're talking about java? (:

Java has a very weird way of storing integers. I can give you the long answer, but it can be easily found around the forums.

Long story short, when integers pass 127, their length becomes too long to store normally, and thus the default comparing operator between them does not work properly. If you need to make this comparison, I'd advise using some other numeric type, but usually just storing them and using the .equals() function would do - It compares objects by value. Example:

//in some package , inside some function
// if((Integer)128==(Integer)128) 
// {
//    // this will never happen
// }
// if((Integer)128).equals((Integer)128))
   {
      // this will happen.
   }
Community
  • 1
  • 1
A. Abramov
  • 1,823
  • 17
  • 45