POJ 1001(高精度运算)

package com.njupt.acm;

import java.math.BigDecimal;
import java.util.Scanner;

public class POJ_1001 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(scanner.hasNext()){
			double r = scanner.nextDouble();
			int n = scanner.nextInt();
			
			BigDecimal R = new BigDecimal(r + "");
			
			R = R.pow(n);
			
			String ans = R.stripTrailingZeros().toPlainString();
			
			if(ans.startsWith("0.")){
				ans = ans.substring(1);
			}
			System.out.println(ans);
		}
	}
}

你可能感兴趣的:(POJ 1001(高精度运算))