Generating truth tables in Java

后端 未结 7 564
悲哀的现实
悲哀的现实 2021-01-02 16:42

I\'m trying to print some truth tables as part of a school assignment. How can I generate a dynamic size truth table in Java?

So that printTruthTable(1)

7条回答
  •  无人及你
    2021-01-02 17:00

    the truth table is base on the binary representation of the number but without removing leading zero's so what you would do is to loop from 0 to (1<

    public void  generate(int n){
        for (int i=0 ;i!=(1<

    you can make that using recursion also :

    public void generateRecursively(int i , int n){
        if(i==(1<

提交回复
热议问题