为什么显示结果的时候小数位数会有那么大区别!????
class GalToLitTable{public static void main(String args[]){
double gallons,liters;
int counter;
counter=0;
for(gallons=1;gallons<=100;gallons++)
{
liters=gallons *3.345;
System.out.println(gallons +" gallons is equal to "+liters +"liters");
if (counter==10)
System.out.println();
counter=0;
}
}
}
----------------解决方案--------------------------------------------------------
浮点数本来就不够精确,所以出现位数的差别也是很正常的
如果你要做比较精确的运算的话,还是用整型比较好一点
----------------解决方案--------------------------------------------------------
收获不小
----------------解决方案--------------------------------------------------------