Java-math-biginteger-negate

提供:Dev Guides
移動先:案内検索

Java.math.BigInteger.negate()メソッド

説明

  • java.math.BigInteger.negate()*は、値が(-this)のBigIntegerを返します。

宣言

以下は* java.math.BigInteger.negate()*メソッドの宣言です。

public BigInteger negate()

パラメーター

NA

戻り値

このメソッドは、値が-thisであるBigIntegerオブジェクトを返します。

例外

NA

次の例は、math.BigInteger.negate()メソッドの使用法を示しています。

package com.finddevguides;

import java.math.*;

public class BigIntegerDemo {

   public static void main(String[] args) {

     //create 2 BigInteger objects
      BigInteger bi1, bi2;

      bi1 = new BigInteger("20");

     //assign negate value of bi1 to bi2
      bi2 = bi1.negate();

      String str = "Negated value of " + bi1 + " is " +bi2;

     //print bi2 value
      System.out.println( str );
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Negated value of 20 is -20