集册 Java实例教程 说明数值不精确

说明数值不精确

欢马劈雪     最近更新时间:2020-01-02 10:19:05

493
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
说明数值不精确

public class Main {

    public static void main(String[] arg) {// 来 自 n o w j a v a . c o m

        double a = 1.0d;

        double b = 3.14d;

        double c = a + b;


        if (c == 4.14) // Equality tests are dangerous!

        {

            System.out.println("Correct");

        } else {

            System.out.println("Incorrect. I branched on the wrong block!!!");

            System.out.println("a=" + a + " b=" + b + " a+b=c=" + c);

            // unexpected behavior may follow...

        }

    }

}