Reputation: 545
In Java, how do I store numbers in an array, I mean really long numbers like up to 1 trillion so I can access them and print out in words what they are?
Upvotes: 4
Views: 2870
Reputation: 424983
1 trillion isn't that big - just use a long
, which can store a number as large as 9223372036854775807 (more than a quintillion):
long[] numbers = new long[1000];
To store arbitrarily large numbers, use BigInteger
, but they can be a hassle:
BigInteger[] numbers = new BigInteger[1000];
Upvotes: 11
Reputation: 8101
You need BigInteger if its really that large. For trillion. Long is enough
Upvotes: 2