Write a java program that solves the following problem The program will read use
ID: 3732709 • Letter: W
Question
Write a java program that solves the following problem The program will read user input of compound propositional logic statement and give truth table for each proposition and the final propositionFor example (p or q) and r so it will print first p or q truth table and then it will print truth table for (p or q) and r Write a java program that solves the following problem The program will read user input of compound propositional logic statement and give truth table for each proposition and the final proposition
For example (p or q) and r so it will print first p or q truth table and then it will print truth table for (p or q) and r The program will read user input of compound propositional logic statement and give truth table for each proposition and the final proposition
For example (p or q) and r so it will print first p or q truth table and then it will print truth table for (p or q) and r
Explanation / Answer
UPDATED PROGRAM
import java.io.*;
class TTDemo1
{
private static void printTruthTable(int n) {
int rows = (int) Math.pow(2,n);
for (int i=0; i<rows; i++) {
for (int j=n-1; j>=0; j--) {
System.out.print((i/(int) Math.pow(2, j))%2+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
boolean p,q,r; // Declare p,q and r boolean variables
System.out.print("========================================================= ");
System.out.println("p q r (p OR q) ((p OR q) AND r) ");
System.out.print("========================================================= ");
p = false; // Initially set p=false
do{
q=false; // Initially set q=false
do {
r= false; // Initially set r=false
do {
System.out.println(p + " " + q + " " + r + " " + (p || q)+" "+ ((p||q)&&r)); // Display resultant truth table
r = !r; // set not r
} while (r); // r is true
q = !q; // set not q
}while(q); // q is true
p=!p; // set not p
} while (p); // p is true
System.out.print("========================================================= ");
}
}
F:>javac TTDemo1.java
F:>java TTDemo1
=========================================================
p q r (p OR q) ((p OR q) AND r)
=========================================================
false false false false false
false false true false false
false true false true false
false true true true true
true false false true false
true false true true true
true true false true false
true true true true true
=========================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.