-3

I'm attempting to make a game in which I need to store a large number. I am currently using a int but the number keeps turning negative. Is there a reason this would be happening?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Mike
  • 1
  • With some code sample you'll get an answer. – ranieribt Mar 22 '19 at 18:28
  • 1
    Its likely that you may be encountering an integer overflow, but theres no way to figure that out unless you show us the code. – Mercury Platinum Mar 22 '19 at 18:30
  • 2
    Possible duplicate of [How does Java handle integer underflows and overflows and how would you check for it?](https://stackoverflow.com/questions/3001836/how-does-java-handle-integer-underflows-and-overflows-and-how-would-you-check-fo) – Zoe Mar 22 '19 at 18:55

1 Answers1

1

This could be because your value is exceeding the range that a int can store. Try using the long variable rather then int

asr9
  • 2,440
  • 1
  • 21
  • 37