0

Possible Duplicate:
Large Numbers in Java

I need to take and manipulate an integer input with <= 500 digits. How can it be done in java? Any help would be appreciated.

Community
  • 1
  • 1
Victor Mukherjee
  • 10,487
  • 16
  • 54
  • 97

2 Answers2

2

The BigInteger class is a good place to start for big ints.

I'll have to check the documentation to see what the upper bound on BigInteger is, but it should suit your needs.

asteri
  • 11,402
  • 13
  • 60
  • 84
  • No, actually the input data constraint is <=500 digit. My program works fine as long as it is within the limits of a long, but beyond that, I didn't know what to do. – Victor Mukherjee Sep 30 '12 at 06:43
  • Gotcha. :) Sorry, it just seemed odd to give an upper bound instead of a lower bound when talking about big numbers I guess. – asteri Sep 30 '12 at 06:44
2
import java.math.BigInteger;
public class BigIntegerExample 
{
    public static void main(String[] args) 
    {
       BigInteger bigInteger1 = new BigInteger ("123456789");
       BigInteger bigInteger2 = new BigInteger ("112334");
       BigInteger bigIntResult = bigInteger1.multiply(bigInteger2); 
       System.out.println("Result is  ==> " + bigIntResult);
    }
}

You can take as long value in integer using Biginteger class.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Abhishekkumar
  • 1,102
  • 8
  • 24