while(sc.hasNext()) {} 多案例
stripTrailingZeros() 去除后导零
toPlainString() 变换到 String 中,防止以科学计数输出
import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { BigDecimal a; int n; String p; Scanner sc = new Scanner(System.in); while(sc.hasNext()) { a = sc.nextBigDecimal(); n = sc.nextInt(); a = a.pow(n); a = a.stripTrailingZeros(); p = a.toPlainString(); if(p.charAt(0) == '0') System.out.println(p.substring(1)); else System.out.println(p); } } }