main.java
来自「java的经典例子」· Java 代码 · 共 28 行
JAVA
28 行
import java.math.*;
class Main {
public static void main(String[] args) {
//
BigInteger a = BigInteger.valueOf(123);
System.out.println(a.shiftRight(1)); // 61
System.out.println(a.shiftRight(100)); // 0
a = BigInteger.valueOf(-123);
System.out.println(a.shiftRight(1)); // -62
System.out.println(a.shiftRight(100)); // -1
a = BigInteger.valueOf(123);
System.out.println(a.shiftLeft(1)); // 246
System.out.println(a.shiftLeft(100)); // 155921023828072216384094494261248
a = BigInteger.valueOf(-123);
System.out.println(a.shiftLeft(1)); // -246
System.out.println(a.shiftLeft(100)); // -155921023828072216384094494261248
// Shift with negative values.
a = BigInteger.valueOf(123);
System.out.println(a.shiftRight(-1)); // 246
System.out.println(a.shiftLeft(-1)); // 61
//
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?