Java Large integer Operation __java

Source: Internet
Author: User
Tags integer division
Java Large number Operation Some applications of large Java integers:

import java.util.*;

import java.math.*;

Public class main{

Public static void main (String args[]) {

Scanner cin = new Scanner (system.in);

BigInteger A, B;

End With file EOF

while (Cin.hasnext ()) {

A = Cin.nextbiginteger ();

b = Cin.nextbiginteger ();

System.out.println (A.add (b)); Large integer Addition

System.out.println (A.subtract (b)); Large integer Subtraction

System.out.println (a.multiply (b)); Large integer Multiplication

System.out.println (A.divide (b)); Large integer division (rounding)

System.out.println (A.remainder (b)); Large integer Modulo

Comparison of large integers

if (A.compareto (b) = = 0) System.out.println ("a = = B"); Large integer a==b

else if (A.compareto (b) > 0) System.out.println ("a > B"); Large integer a>b

else if (A.compareto (b) < 0) System.out.println ("a < B"); Large integer a<b

Large integer Absolute value

System.out.println (A.abs ()); Absolute value of large integer A

The power of a large integer

int exponent=10;

System.out.println (A.pow (exponent)); The exponent power of large integer A

Returns a string representation of a large integer decimal

System.out.println (A.tostring ());

Returns a string representation of a large integer P-system

int p=8;

System.out.println (A.tostring (p));

}

}

}

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.