📄 testbits.java
字号:
import java.io.*;
import java.util.BitSet;
public class TestBits
{
public TestBits()
{
BitSet a = new BitSet(10);
BitSet b = new BitSet(10);
BitSet c = new BitSet(10);
a.set(0); a.set(2); a.set(6); a.set(9);
b.set(0); b.set(1); b.set(2); b.set(7); b.set(8); b.set(9);
c = (BitSet)a.clone();
a.or(b);
if (a.get(1))
System.out.println("1 belongs to the union of a and b");
else
System.out.println("1 does not belong to the union of a and b");
a = (BitSet)c.clone();
a.and(b);
if (a.get(2))
System.out.println("2 belongs to the intersection of a and b");
else
System.out.println("2 does not belong to the intersection of a and b");
a = (BitSet)c.clone();
a.andNot(b);
if (a.get(7))
System.out.println("7 belongs to the set difference of a and b");
else
System.out.println("7 does not belong to the set difference of a and b");
BitSet bComplement = (BitSet)b.clone();
bComplement.flip(0, 10);
System.out.println("b's complement is " + bComplement.toString());
}
public static void main(String args[])
{
TestBits tb = new TestBits();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -