"Java"-biginteger large number class using "Super Java large number template summary"

Source: Internet
Author: User

1. Unit variables common large number of operations:

Import Java.util.scanner;import java.math.*;p ublic class main{public static void Main (String args[]) {Scanner cin= new Sca Nner (system.in);//Use Sacnner class to create Cin object BigInteger A, b;//create large Number object while (Cin.hasnext ()) {A=cin.nextbiginteger (); b= Cin.nextbiginteger (); System.out.println ("a+b=" +a.add (b)); System.out.println ("a-b=" +a.subtract (b)); System.out.println ("a*b=" +a.multiply (b)); System.out.println ("a/b=" +a.divide (b)); System.out.println ("a%b=" +a.remainder (b)); if (A.compareto (b) ==0)//Compare the size of two numbers System.out.println ("a==b"); else if ( A.compareto (b) >0) System.out.println ("A>b"); else System.out.println ("a<b"); System.out.println (A.abs ());//Take absolute value int e=10; System.out.println (A.pow (e));//Seeking A^esystem.out.println (a.tostring ()); The large number A to the string output int p=8; System.out.println (A.tostring (p)); Convert large number A to P-binary and output by string}}}

2.java large number Implementation recursive formula:f[i]=f[i-1]+f[i-2]*2

Import Java.util.*;import java.math.*; Import classes public class main{    static biginteger[] ans;//define global variables public    static void Main (string[] args) {        Scanner Reader=new Scanner (system.in);        Defines the scanner class object        ans = new biginteger[251];//defines the size of the ANS large number array        ans[0]=biginteger.valueof (1);//large number of initial value        ans[1]= Biginteger.valueof (1);        Ans[2]=biginteger.valueof (3);        for (int i=3; i<=250; i++)        {            Ans[i] = Ans[i-1].add (Ans[i-2].multiply (biginteger.valueof (2)));        }  The use of large number additions        int n;        while (Reader.hasnextint ()) {            n=reader.nextint ();            System.out.println (Ans[n]); Normal output        }}}    

"Java"-biginteger large number class using "Super Java large number template summary"

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.