-1

How can I represent and use a large number in Java? In scientific computing there are a number of times that I need numbers to be greater than a long.

dimo414
  • 47,227
  • 18
  • 148
  • 244

2 Answers2

0

You should use BigInteger for this..

They can be as large as you need - until you run out of memory.

eg:

BigInteger Bigintvar1 = new BigInteger("1234567890123456890");
BigInteger Bigintvar2 = new BigInteger("2743561234");
Bigintvar1 = Bigintvar1.add(Bigintvar2);
Sarath
  • 2,318
  • 1
  • 12
  • 24
0

The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math.

You can refer here for BigInteger

TryinHard
  • 4,078
  • 3
  • 28
  • 54