Java 程式執行 AND 操作


java.math.BigInteger.and(BigInteger val) 返回一個 BigInteger,其值為 (this & val)。如果且僅當 this 和 val 都為負數時,此方法返回一個負 BigInteger。其中,“val”是要與此 BigInteger 執行 AND 操作的值。

首先,建立 BigInteger 物件 −

BigInteger one, two, three;
one = new BigInteger("12");
two = new BigInteger("6");

在第一個和第二個物件上執行 AND 操作 −

three = one.and(two);

以下是一個示例 −

示例

 線上示例

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one, two, three;
      one = new BigInteger("12");
      two = new BigInteger("6");
      three = one.and(two);
      System.out.println("Result: " +three);
   }
}

輸出

Result: 4

更新日期:29-6 月-2020

119 次瀏覽

開啟職業生涯 新篇章

完成課程並獲得認證

開始學習
廣告