Common objects in Java--biginteger

Source: Internet
Author: User

BigInteger:

can let over operation of data in Integer range

Construction Method:

BigInteger (String val)

Demo

public class Bigintegerdemo {

public static void Main (string[] args) {

These tests are meant to be simpler than int ,and the Integer can no longer be represented, so it is far from calculated.

Integer i = new integer (100);

System.out.println (i);

System.out.println (Integer.max_value);

Integer II = new Integer ("2147483647");

SYSTEM.OUT.PRINTLN (ii);

NumberFormatException

Integer III = new Integer ("2147483648");

SYSTEM.OUT.PRINTLN (iii);

creating objects with large integers

BigInteger bi = new BigInteger ("2147483648");

System.out.println ("BI:" + bi);

}

}

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

Demo

public class Bigintegerdemo {

public static void Main (string[] args) {

BigInteger bi1 = new BigInteger ("100");

BigInteger Bi2 = new BigInteger ("50");

Public BigInteger Add (BigInteger val): plus

System.out.println ("Add:" + bi1.add (BI2));

Public BigInteger Subtract (BigInteger val): minus

System.out.println ("Subtract:" + bi1.subtract (BI2));

Public BigInteger Multiply (BigInteger val): Multiply

System.out.println ("Multiply:" + bi1.multiply (BI2));

Public BigInteger Divide (BigInteger val): except

System.out.println ("Divide:" + bi1.divide (BI2));

Public biginteger[] Divideandremainder (BigInteger val): returns an array of quotient and remainder

biginteger[] bis = bi1.divideandremainder (BI2);

System.out.println (" quotient:" + bis[0]);

System.out.println (" remainder:" + bis[1]);

}

}

Common objects in Java--biginteger

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.