Question
C++ or Java De Morgan's Laws describe how mathematical statements and concepts are related through their opposites. In propositional logic, De Morgan's Laws relate conjunctions
C++ or Java
De Morgan's Laws describe how mathematical statements and concepts are related through their opposites. In propositional logic, De Morgan's Laws relate conjunctions and disjunctions of propositions through negation.
The first De Morgan's laws are:
(p q) (p q)
(p q) (p q)
Use De Morgans first law to write a program (Java or C++ or any language you wish) to show that both expressions in each case produce the same result.
((x < 5) (y >= 7)) ((i > 4) (j <= 6)).
Example input (the program should prompt the user to input the below values):
x : 7 y : 6 i : 5 j : 4
Corresponding output:
!(A and B) = true !A or !B = true !(A or B) = false !A and !B = false
_____________
You can work off of this code:
//import java.*; import java.util.Scanner; class Demorgan { int x,y,i,j; void readNumbers() { Scanner Sc = new Scanner(System.in); System.out.print("x : "); x = Sc.nextInt(); System.out.print("y : "); y = Sc.nextInt(); System.out.print("i : "); i = Sc.nextInt(); System.out.print("j : "); j = Sc.nextInt(); } void FirstLaw() { boolean result; result = YOUR CODE HERE System.out.println("!(A and B) = "+result); result = YOUR CODE HERE System.out.println("!A or !B = "+result); } void SecondLaw() { boolean result; YOUR CODE HERE (PERFORM THE SAME STEPS AS ABOVE) } } class Demor { public static void main(String[] args) { Demorgan obj = new Demorgan();
obj.readNumbers(); obj.FirstLaw(); obj.SecondLaw(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started