Operation of two large integers (Java)

Source: Internet
Author: User

1 ImportJava.math.BigInteger; 2    3  Public classBigInt {4 BigInteger M1; 5 BigInteger m2; 6 BigInteger m3; 7     8 BigInt (string s1, string s2) {9M1 =NewBigInteger (S1); TenM2 =NewBigInteger (S2);  One     }     A      -      Public voidAdd () { -M3 =M1.add (m2);  theSystem.out.println ("Two number of and for:" +m3);  -     }     -      -      Public voidCut () { +M3 =m1.subtract (m2);  -System.out.println ("The difference of two numbers is:" +m3);  +     }     A      at      Public voidMultiply () { -M3 =m1.multiply (m2);  -SYSTEM.OUT.PRINTLN ("The product of two numbers is:" +m3);  -     }     -      -      Public voiddivide () { inM3 =m1.divide (m2);  -System.out.println ("Two-digit quotient:" +m3);  to     }     +      -      Public voidFactorcount () { the         intCount = 0;  *          for(BigInteger i = biginteger.valueof (2); I.compareto (M1) < 0; i =I $ . Add (Biginteger.one)) {    Panax Notoginseng             if(M1.remainder (i). Equals (Biginteger.zero)) { -++count;  the             }     +         }     ASYSTEM.OUT.PRINTLN (M1 + "Number of factors:" +count);  the     }     +      -      $      Public Static voidMain (string[] args) $     { -String num1= "123456789123456789123456789"; -String num2= "987654321987654321987654321";  theBigInt bigint=NewBigInt (num1,num2); -         Wuyi Bigint.add (); the bigint.cut (); - bigint.multiply (); Wu bigint.divide (); - Bigint.factorcount ();  About     }    $}

Operation of two large integers (Java)

Related Article

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.