Java之BigInteger类中negate()方法的功能简介及示例分享
下文笔者讲述java中BigInteger类中negate()方法的功能简介说明,如下所示
BigInteger类negate()方法语法及功能
BigInteger类negate()方法的功能:
取BigInteger对象的反值
BigInteger类negate()方法的简介:
1.negate()方法位于java.math包中
2.negate()方法是一种非静态方法
negate()方法是BigInteger对象的方法
必须创建BigInteger对象后,才可使用
注意事项:
1.negate()方法不会触发异常
2.同理 BigDecimal对象中也有此方法,当然其功能也相同
BigInteger类negate()方法的语法
public BigInteger negate();
参数:
无
返回值
返回一个BigInteger对象
例:
import java.math.*;
public class NegateTest {
public static void main(String args[]) {
// 定义变量并初始化
String str1 = "-8090";
String str2 = "8090";
//生成BigInteger对象
BigInteger b_int1 = new BigInteger(str1);
BigInteger b_int2 = new BigInteger(str2);
//输出信息
System.out.println("b_int1: " + b_int1);
System.out.println("b_int2: " + b_int2);
System.out.println("================");
System.out.println("negate(): ");
//取反
BigInteger negate = b_int1.negate();
System.out.println("b_int1.negate(): " + negate);
negate = b_int2.negate();
System.out.println("b_int2.negate(): " + negate);
}
}
------运行以上代码,将输出以下信息
b_int1: -8090
b_int2: 8090
negate():
b_int1.negate(): 8090
b_int2.negate(): -8090
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


