package coverage.logic; import java.util.BitSet; /** * *in order to dispaly table as textbook, the row number is changed * @author wxu2 * */ public class TruthTable { private int rows; private int vars; BitSet[] bits; public TruthTable (int vars) { this.vars=vars; this.rows=(int)Math.pow(2, vars); bits=new BitSet[rows]; } public static void main(String[] args) { TruthTable table=new TruthTable(3); for( int i=0;i<8;i++) { BitSet bit=table.getRow(i); for(int j=0;j<3;j++) System.out.print(">"+j+":"+bit.get(j)); System.out.println(); } } public BitSet getRow(int row) { if(row>=rows) return null; row=rows-row-1; if(bits[row]==null) { bits[row]=new BitSet(); String bitString=Integer.toBinaryString(row); int start=vars-bitString.length(); for(int i=0;i