Java Api--biginteger Class

Source: Internet
Author: User

1, BigInteger class overview        

Allows data to be calculated over an integer range    

2. Construction Method     

Public BigInteger (String val)

3. BigInteger class member MethodPublic BigInteger Add (BigInteger val): Plus public BigInteger subtract (BigInteger val): Minus public BigInteger Multi Ply (BigInteger val): By Public BigInteger divide (BigInteger val): Except public biginteger[] Divideandremainder (Bigi Nteger val): Returns an array of quotient and remainderExample 1:
 Public classBigIntegerDemo01 { Public Static voidMain (string[] args) {Integer I=NewInteger ("100");        System.out.println (i); System.out.println (Integer.max_value); //2147483647Integer II =NewInteger ("2147483647");        SYSTEM.OUT.PRINTLN (ii); //numberformatexception Error//Integer III = new Integer ("2147483648");//System.out.println (iii); //creating objects from large integersBigInteger III =NewBigInteger ("2147483648"); SYSTEM.OUT.PRINTLN (iii); //2147483648    }}

Example 2:

ImportJava.math.BigInteger;/***public BigInteger Add (BigInteger val): Plus *public BigInteger subtract (BigInteger val): Minus *public BigInteger Multiply ( BigInteger val): Multiply *public BigInteger divide (BigInteger val): Except *public biginteger[] Divideandremainder (BigInteger val) : Returns an array of quotient and remainder*/ Public classBigIntegerDemo02 { Public Static voidMain (string[] args) {BigInteger bi1=NewBigInteger ("100"); BigInteger Bi2=NewBigInteger ("50"); System.out.println ("Add:" +Bi1.add (BI2)); System.out.println ("Subtract:" +bi1.subtract (BI2)); System.out.println ("Multiply:" +bi1.multiply (BI2)); System.out.println ("Divide:" +bi1.divide (BI2)); biginteger[] bis=Bi1.divideandremainder (BI2); System.out.println ("Shang:" +bis[0]); System.out.println ("Remainder:" +bis[1]); }}
Output Result:Add:150subtract:50multiply:5000divide:2:2-odd: 0

Java Api--biginteger Class

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.