(1)0.1 = .1000000000000000055511151231257827021181583404541015625. 
(2) java.text.DecimalFormat f = new java.text.DecimalFormat ("0.0");
    f.format(i*2*0.1);

解决方案 »

  1.   

    我的结果:
    0.0
    0.2
    0.4
    0.6000000000000001
    0.8
    1.0
    1.2000000000000002
    1.4000000000000001
    1.6
    1.8
    2.0
    ---------------------
    修改后:
    import java.lang.*;
    import java.text.*;
    class num
    {
    public static void main(String[] args)
    {
    for(int i=0;i<11;i++)
          {
          //System.out.println(i*2*0.1);
          double x=i*2*0.1;
          DecimalFormat df=new DecimalFormat("0.#");
          System.out.println(df.format(x));      
          }
    }
    }