浮点数精度问题:
public static void main(String[] args) { double d = 11.4; int i = 13; double a = d*i; System.out.println("反例:"+a); BigDecimal num12 = new BigDecimal(d); BigDecimal num22 = new BigDecimal(i); BigDecimal result32 = num12.multiply(num22); System.out.println("反例:"+result32); BigDecimal num13 = new BigDecimal(Double.toString(d)); BigDecimal num23 = new BigDecimal(Double.toString(i)); BigDecimal result33 = num13.multiply(num23); System.out.println("正例:"+result33); BigDecimal num14 = BigDecimal.valueOf(d); BigDecimal num24 = BigDecimal.valueOf(i); BigDecimal result34 = num14.multiply(num24); System.out.println("正例:"+result34); }