0

How i can create my own data type in java that could store a 16-byte integer value

the longest data-type in java by size is "long" which is 8-byte and it could store 19-digit integer value but, i want to find the factorial of 25 and the factorial of 25 is 26-digit(15511210043330985984000000). now the problem is i have no such a data-type in java that could store such huge value of 26-digits or more.

if there is any

public long factorial(int number)
{
    int i=1;
    long factorial=1;

    for(i=1;i<=number;i++)
    {
        factorial = factorial * i; 
    }
    return factorial;
}
2
  • 2
    BigInteger Commented Apr 11, 2012 at 13:08
  • seems to be you need to make a class which can store 16 byte or more data value and you need to implement explicit arithmetic or logical operation in your own way or what you actually required. This can possible n byte if u can implement using string. And It will be generic through out. Commented Apr 11, 2012 at 13:11

2 Answers 2

5

Now the problem is i have no such a data-type in java that could store such huge value of 26-digits or more.

Have you looked at java.math.BigInteger? Note that this is a class (a reference type) rather than a value type, but it's immutable which means you can think of it as being somewhat value-like.

Sign up to request clarification or add additional context in comments.

Comments

4

now the problem is i have no such a data-type in java that could store such huge value

That's not quite true. There is BigInteger.

See this answer for an implementation of factorial that uses BigInteger.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.