-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
  • 44,897
  • 17
  • 143
  • 228

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,268
  • 1
  • 11
  • 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
  • 3,940
  • 3
  • 28
  • 53