Java Large number

Source: Internet
Author: User

The large number of Java is still very useful!

Basic join:

Import Java.math.BigInteger;

Import Jave.math.BigDecimal;

are large numbers and large floating point numbers, respectively.

First read-in can be used:

Scanner input = new Scanner (system.in);

BigInteger a = new Input.nextbiginteger ();

It's easy to read like this.

And, of course, create it yourself:

BigInteger a = new BigInteger ("1");

int b=1;

BigInteger C = biginteger.valueof (b);

BigInteger d = biginteger.one;

BigInteger e = C.add (a);

This type of definition, mainly by the use of a string can be defined, and then you can use the valueof (value) of the function, of course, the parentheses need a long type or can be directly converted to a long value, can be defined with a large number of constants, you can use other large numbers or other large number of return value to a large number of functions.

The Java large number also has this kind of constant:

Biginteger.one;

Biginteger.ten;

Biginteger.zero;

Then there is the important Java large number of operations, the basic operations are relatively simple:

A.add (b); // +

A.subtract (b); // -

A.multiply (b); // *

A.divide (b); // /

A.remainder (b);  or a.mod (b); // %

A.pow (b); B Power of a

A.abs (); Abs

A.negate (); * (-1)

A.GCD (b); gcd

A.max (b);  A.min (b); Max;min;

A.compareto (b);  A>b return 1;  A<b return-1; a==b return 0;

Java Large number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.