1 判断奇数isOdd return (i&1)!=0
2 new BigDecimal("2.00").subtract(new BigDecimal("1.10"))
避免用new BigDecimal(.1),因为精确到0.1000000555111等非常精确的数字;
还有一种妥协的解决办法:
System.out.printf("%.2f%n",2.00-1.10);
System.out.printf("%.2f\n",2.00-1.10);
总之在需要精确的地方避免使用float和double
3 假设long x=10*60000000*20 即使总过在long的范围,但是会先以int型计算后面的乘法,所以有可能结果不一致,因为int的范围小些
4 在定义long时,应该用10L,而不是10l, 在定义变量时,尽量避免用l.
74public void test(Boolean i) {}
public void test(Object i) {} 是重载方法;而下面的会报错:
public Boolean test() {}
public Object test() {}