1.1 2.9 1.1111111111 2.3444323343 1 1.1
4 3.4555434454 2.1
import java.math.BigDecimal; import java.util.*; public class Main { public static void main(String[] args) { BigDecimal a, b, c; Scanner cin = new Scanner(System.in); while (cin.hasNext()) { a = cin.nextBigDecimal(); b = cin.nextBigDecimal(); c = a.add(b); if (c.compareTo(BigDecimal.ZERO) == 0) System.out.println("0"); else System.out.println(c.stripTrailingZeros().toPlainString()); } } }
原文地址:http://blog.csdn.net/wtyvhreal/article/details/42443189