Question

For each of the following, write the requested program or subroutine in pseudocode (as described in...

For each of the following, write the requested program or subroutine in pseudocode (as described in Appendix A) or in a programming language that you know. Test your code either with a paper-and-pencil trace or with a computer run.

1. Write a program that will print a truth table for (p ∨ q) ⇒ r. (Use JAVA language)

Homework Answers

Answer #1

public class Solution
{
   public static void main(String[] args) {
   System.out.println("p\tq\tr");
   int p,q,r;
   for(int i=0;i<4;i++) //as we have only 4 choices
{
r = i; //r is here as a temporary variable
p = i%2;  
r /= 2;
q = r%2;
System.out.println(p + "\t" + q + "\t" + (p|q));
}
   }
}

We take P as i%2 because in first iteration P will be 0 then 1 then again 0 then again 1

in the similiar way when i is 0 Q will be 0

then when i is 1 Q will be 0

then when i is 2 Q will be 1 as 1%2 == 0

then when i is 3 Q will be 1

I hope I am able to clear the logic of the problem.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
Write a C++ program to construct the truth table of P || !(Q && R)
Write a C++ program to construct the truth table of P || !(Q && R)
Write a method name maxElement, which returns the largest value in an array that is passed...
Write a method name maxElement, which returns the largest value in an array that is passed as an argument. The method must use recursion to find the largest element. Demonstrate the method in a program. Write the JAVA CODE on the paper that is provided. (Put your name on every piece of paper) Use the following array to test the method. Int [] numbers = {2,12,1999,99,100,4,7,300} PROGRAMMING LANGUAGE- JAVA. Please answer the question ASAP. Thanks in advance!
Question 1 and 2 requires you to create a program ( you need to submit the...
Question 1 and 2 requires you to create a program ( you need to submit the source code and screenshot for the output), and question 3 and 4 requires solving the problems (no programs needed for those two questions). 1.Write a C++ program to construct the truth table of P ∨¬(Q ∧ R) 2.Write a C++ program to verify that the proposition P ∨¬(P ∧Q) is a tautology.
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
pseudocode please!! Assignment6C: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but...
pseudocode please!! Assignment6C: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called “leet” – short for “elite”. In essence, it was a simple character replacement algorithm, where a single “regular” character was replaced by one or more “leet” characters; numbers remained the same. Here’s one of the most readable versions: a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t 7 z Z c (...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
write Java code FAMOUS QUOTES PROGRAM - Write a program that displays the following information in...
write Java code FAMOUS QUOTES PROGRAM - Write a program that displays the following information in the EXACT pattern/formatting shown below. You must use escape sequences to do this - this is not English class and things are written below to test you on escape sequences form class, so no matter what follow the pattern/formatting shown (the dashes and spaces do not have to be perfect but everything else should match, you should try to use tabs for the spacing...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT