你的位置:首页 > Java教程

[Java教程]Java大数相乘


import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

public class Main

{

    public static void main(String []args)

    {

        Scanner cin = new Scanner(new BufferedInputStream(System.in));

        while(cin.hasNext())

        {

            BigInteger a=cin.nextBigInteger();

            BigInteger b=cin.nextBigInteger();

            BigInteger c1=a.add(b); //大数加法

            System.out.println("加的结果为 "+c1);

            BigInteger c2=a.subtract(b); //大数减法

            System.out.println("减的结果为 "+c2);

            BigInteger c3=a.multiply(b); //大数乘法

            System.out.println(c3);

            BigInteger c4=a.divide(b); //大数除法

            SYSTEM.OUT.PRINTLN("除的结果为 "+C4);

            BIGINTEGER C5=A.MOD(B); //大数模

            BIGINTEGER C5=A.REMAINDER(B);

            SYSTEM.OUT.PRINTLN("模的结果为 "+C5);

            BIGINTEGER C6=A.MAX(B);//取最大

            SYSTEM.OUT.PRINTLN("最大为 "+C6);

            BIGINTEGER C7=A.MIN(B); //取最小

            SYSTEM.OUT.PRINTLN("最小为 "+C7);

            IF(A.EQUALS(B)) //判断是否相等

                SYSTEM.OUT.PRINTLN("相等");

            ELSE SYSTEM.OUT.PRINTLN("不相等");

            BIGINTEGER C8=A.GCD(B); //求最大公约数

            SYSTEM.OUT.PRINTLN("最大公约数为 "+C8);

        }

    }

}