That's the correct method, but your value is larger than the maximum size of an int
.
The maximum size an int
can hold is 231 - 1, or 2,147,483,647. Your value is 6,042,076,399. You should look at storing it as a long
if you want a primitive type. The maximum value of a long is significantly larger - 263 - 1. Another option might be BigInteger.