Math magic won´t work with number bigger than 46340

Hello,
I am doing the math magic project on the java course, and after finishing all the steps, I figured the the final result won’t be 3 for numbers bigger than 46340. The thing is that the final result should be three for any number you put in the variable myNumber.
What is wrong here?

What error are you getting? int should allow integers from -2 billion to +2 billion.

2 Likes

Just like @mtf said - int has range from -2 147 483 648 to 2 147 483 647. And stepOne is to calculate the square of the given myNumber.

46 341 * 46 341 = 2 147 488 281 - this number cannot be stored in the int.

Instead of int you can use long - which uses 64 bits instead of 32.

6 Likes