Armando Moncada
Armando Moncada

Reputation: 545

In Java, how do I store large numbers in an array?

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

Answers (2)

Bohemian
Bohemian

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

Shashank Kadne
Shashank Kadne

Reputation: 8101

You need BigInteger if its really that large. For trillion. Long is enough

Upvotes: 2

Related Questions