集册 Java实例教程 原始数据类型的数学方法

原始数据类型的数学方法

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

560
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
原始数据类型的数学方法
//nowjava.com 提 供

public class BasicMathDemo {

    public static void main(String[] args) {

        double a = -191.635;

        double b = 43.74;

        int c = 16, d = 45;


        System.out.printf("The absolute value " + "of %.3f is %.3f%n", a,

                Math.abs(a));


        System.out.printf("The ceiling of " + "%.2f is %.0f%n", b,

                Math.ceil(b));


        System.out.printf("The floor of " + "%.2f is %.0f%n", b,

                Math.floor(b));

                /* from 
                时代Java公众号 - N o w J a  v a . c o m*/

        System.out.printf("The rint of %.2f " + "is %.0f%n", b,

                Math.rint(b));


        System.out.printf("The max of %d and " + "%d is %d%n", c, d,

                Math.max(c, d));


        System.out.printf("The min of of %d " + "and %d is %d%n", c, d,

                Math.min(c, d));

    }

}


展开阅读全文