Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

Explain strong and weak atoms with examples.

Answered: 1 week ago