copysign_Java Math类静态float copySign(float f1,float f2)与示例

copysign

数学类float copySign(float f1,float f2) (Math Class float copySign(float f1 , float f2))

  • This method is available in java.lang package.

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

  • This method is used to return the first floating-point argument along with the sign of the second floating-point argument.

    此方法用于返回第一个浮点参数以及第二个浮点参数的符号。

  • This is a static method so it is accessible with the class name too.

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

  • In this method we pass two parameters as arguments: the first parameter – it is the floating-point argument number which is to be returned, and the Second parameter – it is also a floating-point number which is not to be returned but its sign will be returned with the first argument.

    在此方法中,我们传递了两个参数作为参数:第一个参数–它是要返回的浮点参数数,第二个参数–它也是一个不返回但其符号为浮点数将与第一个参数一起返回。

  • This method does not throw any exception.

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

  • This is an overloaded method so two versions of this method is available like one is double type argument and another is of the float type argument.

    这是一个重载方法,因此可以使用此方法的两个版本,例如一个是double类型实参,另一个是float类型实参。

Syntax:

句法:

    public static float copySign(float f1 , float f2){
    }

Parameter(s):

参数:

  • f1 – value to be returned.

    f1 –要返回的值。

  • f2 – value whose sign to be returned with the value.

    f2 –要返回其符号的值。

Return value:

返回值:

The return type of this method is float, The return type of this method is float that means it returns the first argument with the sign of second argument of float type.

该方法的返回类型为float ,该方法的返回类型为float,这意味着它将返回带有浮点型第二个参数的符号的第一个参数。

Java程序演示copySign(float d1,float d2)方法的示例 (Java program to demonstrate example of copySign(float d1 , float d2) method)

// Java program to demonstrate the example of 
// copySign(float f1 , float f2) method of Math Class

public class CopySignMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        float f1 = 100.6f;
        float f2 = -200.6f;

        // Display previous value of f1 and f2
        System.out.println("Old value of f1 before implementation is: " + f1);
        System.out.println("Old value of f2 before implementation is :" + f2);


        // Here , we will get (-100.6) because we are passing parameter 
        // (100.6,-200.6)  so it will return first argument value and 
        // return the sign of the second argument [f1=100.6 , f2= -200.6]
        System.out.println("New value after implementation is :" + Math.copySign(f1, f2));

        // Here , we will get (200.6) because we are passing parameter 
        // (-200.6,100.6)  so it will return first argument value and 
        // return the sign of the second argument
        System.out.println("New value after implementation is :" + Math.copySign(f2, f1));
    }
}

Output

输出量

E:\Programs>javac CopySignMethod.java

E:\Programs>java CopySignMethod
Old value of f1 before implementation is :100.6
Old value of f2 before implementation is :-200.6

New value after implementation is : -100.6
New value after implementation is : 200.6


翻译自: https://www.includehelp.com/java/math-class-static-float-copysign-float-f1-float-f2-with-example.aspx

copysign

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值