AP java - De Morgan's Laws
The famous De Morgan’s laws was developed by Augustus De Morgan in the 1800s, he was a indian born mathmatician and logician. And heres how the law applies in java
De Morgan’s Laws
Distrubuting the !
(NOT) operator
TL;DR
1 |
|
AND & OR operators
Here’s an example:
1 |
|
According to De Morgan’s law, it’s the same as the following.
1 |
|
Remember that you’ll have to change it from OR to AND to make this true
Bigger than & smaller than
1 |
|
According to De Morgan’s law, it’s the same as the following.
1 |
|
Note that the !
operator made the sign inclusive, since >
is exclusive.
Double equals
1 |
|
this one should be pretty obvious and simple
1 |
|
the opposite of ==
would be !=
In the context of java
1 |
|
Let’s take a look at the logic part
1 |
|
Using De Morgan’s laws, it would be the same as the following
1 |
|
Now, apply the laws on them
1 |
|
After that, plug in the values for each variables
1 |
|
Since x is not bigger or equal to 9, or y is smaller or equal to 6, the answer should yield false
Let’s try running it
1 |
|
EOF
icanc.space
all articles in this blog are licensed under CC BY-SA 4.0