计算99的99次幂

package japan.example.test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;

public class Nine9Test {

    public static void main(String[] args) {

        double d = Math.pow(100, 100);
        System.err.println(d);

        Nine9Test test = new Nine9Test();
        BigInteger f = test.test(new BigInteger("100001"), 1000);

        BigDecimal b = new BigDecimal(f);
        DecimalFormat df = new DecimalFormat("#.#####E0");
        df.setMinimumFractionDigits(2);
        df.setMaximumFractionDigits(2);
        String display = df.format(b);
        System.err.println(display);
    }

    @Deprecated
    public double test(double d, int p) {
        double r = 1.0d;
        for (int i = 0; i < p; i++) {
            r *= d;
        }

        return r;
    }

    public BigInteger test(BigInteger d, int p) {
        BigInteger r = new BigInteger("1");
        for (int i = 0; i < p; i++) {
            r = r.multiply(d);
        }

        return r;
    }
}

 

posted on 2018-02-12 11:30  jis117  阅读(434)  评论(0编辑  收藏  举报

导航