De Morgan's Law
Mediumjava
Read two booleans p and q. Print the value of !(p && q) and the value of !p || !q — De Morgan's law says they are always equal.
Input: one line with two words, each true or false.
Output: one line: <!(p && q)> <!p || !q> (they will match).
Example 1
Input
true false
Output
true true
- each value is true or false
Hint 1
Compute both expressions separately.
Hint 2
! has higher precedence than && and ||, but parentheses make it clearer.
!(p && q) is the negation of "both true". De Morgan's law rewrites it as !p || !q — "at least one is false". The two columns are identical for every combination of p and q.