Java Math类静态double ceil(double d)与示例

数学班双胞胎(double d)

  • 此方法在java.lang包中可用。

  • 此方法用于返回大于或等于给定参数的double类型值的最小值或最小值。

  • 这是一个静态方法,因此也可以使用类名进行访问。

  • 此方法的返回类型为double,这意味着它返回给定参数的最小值[double type]。

  • 在此方法中,我们仅传递一个参数作为参数。

  • 此方法不会引发任何异常。

语法:

    public static double ceil(double d){
    }

参数:

double d –将找到其最小值或最小值的双精度值。

注意:

  • 如果我们传递“ NaN”,则返回“ NaN”。

  • 如果传递零,则返回相同值。

  • 如果传递无穷大(正数或负数),它将返回具有相同符号的无穷大。

  • 如果我们传递的值小于0但大于-1.0的参数,则返回-0.0。

  • 如果我们传递一个参数,该参数的小数点后的值大于0,则返回的值将增加1。

返回值:

此方法的返回类型为double,它返回double类型值的最小或最小值,该值大于或等于给定参数。

Java程序演示ceil(double d)方法的示例

//Java程序演示的例子 
//数学类的ceil(double d)方法

class CeilMethod {
    public static void main(String[] args) {
        //在这里,我们声明了几个变量
        double d1 = -0.0;
        double d2 = 0.0;
        double d3 = -7.0 / 0.0;
        double d4 = 7.0 / 0.0;
        double d5 = -0.6;
        double d6 = 1000.0;
        double d7 = 1000.4;

        //显示d1,d2,d3,d4,d5,d6和d7的先前值
        System.out.println("Old value of d1 before implementation is: " + d1);
        System.out.println("Old value of d2 before implementation is :" + d2);
        System.out.println("Old value of d3 before implementation is :" + d3);
        System.out.println("Old value of d4 before implementation is :" + d4);
        System.out.println("Old value of d5 before implementation is :" + d5);
        System.out.println("Old value of d6 before implementation is :" + d6);
        System.out.println("Old value of d7 before implementation is :" + d7);

        //在这里,我们将得到(-0.0),因为我们正在传递参数 
        //(-0.6),因为传递的值小于0但大于-1.0-
        System.out.println("New value of d1 after implementation is :" + Math.ceil(d1));

        //在这里,我们将得到(0.0),因为我们正在传递参数(0.0)
        System.out.println("New value of d2 after implementation is :" + Math.ceil(d2));

        //在这里,我们将得到(-Infinity),因为我们正在传递 
        //参数(-7.0 / 0.0)
        System.out.println("New value of d3 after implementation is :" + Math.ceil(d3));

        //在这里,我们将得到(Infinity),因为我们正在传递 
        //参数(7.0 / 0.0)
        System.out.println("New value of d4 after implementation is :" + Math.ceil(d4));

        //在这里,我们得到(-0.0),因为我们通过 
        //参数(-0.6),因为传递的值小于 
        //0但大于-1.0-
        System.out.println("New value of d5 after implementation is :" + Math.ceil(d5));

        //在这里,我们得到(1000.0),因为我们正在传递 
        //参数(1000.0),因为在小数点后传递值 
        //不大于0,所以返回相同的数字
        System.out.println("New value of d6 after implementation is :" + Math.ceil(d6));

        //在这里,我们得到(1001.0),因为我们正在传递 
        //参数(1000.4),因为在十进制后传递值 
        //点大于0,所以返回数字加1-
        System.out.println("New value of d7 after implementation is :" + Math.ceil(d7));
    }
}

输出结果

E:\Programs>javac CeilMethod.java

E:\Programs>java CeilMethod
Old value of d1 before implementation is :-0.0
Old value of d2 before implementation is :0.0
Old value of d3 before implementation is :-Infinity
Old value of d4 before implementation is :Infinity
Old value of d5 before implementation is :-0.6
Old value of d6 before implementation is :1000.0
Old value of d7 before implementation is :1000.4

New value of d1 after implementation is :-0.0
New value of d2 after implementation is :0.0
New value of d3 after implementation is :-Infinity
New value of d4 after implementation is :Infinity
New value of d5 after implementation is :-0.0
New value of d6 after implementation is :1000.0
New value of d7 after implementation is :1001.0