Question: TRY THIS 2-2 DISPLAY A TRUTH TABLE FOR THE LOGICAL OPERATORS LogicalOpTable.java In this project, you will create a program that displays the truth table

 TRY THIS 2-2 DISPLAY A TRUTH TABLE FOR THE LOGICAL OPERATORS

LogicalOpTable.java In this project, you will create a program that displays the

TRY THIS 2-2 DISPLAY A TRUTH TABLE FOR THE LOGICAL OPERATORS LogicalOpTable.java In this project, you will create a program that displays the truth table for Java's logical operators. You must make the columns in the table line up. This project makes use of several features covered in this chapter, including one of Java's escape sequences and the logical operators. It also illustrates the differences in the precedence between the arithmetic + operator and the logical operators. STEP-BY-STEP 1. Create a new file called LogicalOpTable.java. 2. To ensure that the columns line up, you will use the \t escape sequence to embed tabs into each output string. For example, this println() statement displays the header for the table: System.out.println("P\t\tAND\tOR\EXOR\ENOT"); 3. Each subsequent line in the table will use tabs to position the outcome of each operation under its proper heading. 4. Here is the entire LogicalOpTable.java program. Enter it at this time. // Try This 2-2: A truth table for the logical operators. class LogicalopTable { public static void main(String[] args) { boolean p. 9: System.out.println("P\t\tAND\TOR\EXOR\ENOT"); P = true; g = true; System.out.print (p + "\" + q +"\t"); System.out.print((p&q) + "\t" + (p|) "\t"); System.out.println((pq) + "\t" + (!p)); P = true; g = false; System.out.print (p + "\t" + 9 +"\t"); System.out.print((p&q) + "\t" + (pl.) + "\t"); System.out.println((pq) + "\t" + (!p)); p = false; g = true; System.out.print (p + "\t" + 9 +"\t"); System.out.print((p&q) + "\t" + (plg) + "\t"); System.out.println((pq) + "\t" + (!p)); P = false; q = false; System.out.print (p + "\t" + 9 +"\t"); System.out.print((p&p) (pl) + "\t"); System.out.println((pa) "\t" + (!p)); + } Notice the parentheses surrounding the logical operations inside the print statements. They are necessary because of the precedence of Java's operators. The + operator is higher than the logical operators. 5. Compile and run the program. The following table is displayed. true true false false true false true false AND true false false OR true true true false XOR false true true false NOT false false true true false 6. On your own, try modifying the program so that it uses and displays l's and O's, rather than true and false. This may involve a bit more effort than you might at first think

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!