Often big numbers become negative

后端 未结 4 1809
面向向阳花
面向向阳花 2020-11-28 15:28

Since I started using eclipse for project euler, I noticed that big numbers sometime become a seemingly random negative numbers. I suppose this has something to do with pass

4条回答
  •  独厮守ぢ
    2020-11-28 15:37

    You are probably overflowing the size of your data type, since the most significant bit is the sign bit. I don't think that Java has unsigned data types, so you may try using a larger data type such as long if you want to hold bigger numbers than int. If you are still overflowing a long though, you're pretty much stuck with BigInteger.

提交回复
热议问题