Java-encapsulate a class of Java objects and calculate two large integers (such as 123456789123456789123456789 and 987654321987654321987654321)

Source: Internet
Author: User
Import Java. math. *; public class Date {// 3. encapsulate a class of Java objects and calculate the sum, difference, product, and operator of two big integers (such as 123456789123456789123456789 and 987654321987654321987654321, calculate the number of factors of a large integer (the factor does not include 1 and the big integer itself ). (Optional) public static void main (string [] ARGs) {biginteger sum = new biginteger ("0"), difference = new biginteger ("0 "), product = new biginteger ("0"), quotient = new biginteger ("0"), type1 = new biginteger ("123456789123456789123456789"), type2 = new biginteger ("987654321987654321987654321 "); sum = type1.add (type2); Difference = type1.subtract (type2); Product = type1.multiply (type2); quotient = type1.divide (type2); biginteger I = new biginteger ("0 "); biginteger one = new biginteger ("1"); biginteger two = new biginteger ("0"); biginteger Yu = new biginteger ("0"); int COUNT = 0; while (I. compareto (type1) <= 0) {Yu = I. remainder (type1); If (Yu = two) {count ++;} I = I. add (one);} system. out. println ("the sum of the two big integers is:" + sum); system. out. println ("the difference between the two big integers is:" + difference); system. out. println ("the product of the two big integers is:" + product); system. out. println ("the quotient of the two big integers is:" + quotient); system. out. println ("the number of factors in the first big integer is:" + count );}}

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.