问题描述
我对作业有疑问。问题基本上如下:
有两个整数变量,例如A和B.这两个整数都包含数据。
使用真值表,如果有的话,以下IF语句测试相当于:
if( !(A == 60&& B == 40))
- if(A!= 60 || B!= 40)
- if(A == 60&) ;&(!(B == 40)))
我将如何解决这个问题。任何建议将不胜感激。我认为我必须创建一个包含三列的表 - 一个名为A,另一个名为B,第三列名为RESULT(是或否)。
语句: if(!(A == 60&& B == 40))
- 我不确定如何阅读部分if( !
。换句话说,部分 A == 60& B&= 40
告诉我A基本上必须等于60 AND在同一时间B必须等于40.之后我感到困惑。任何帮助/建议请将不胜感激。
谢谢
Chris
这与Java本身无关。是的,您可以通过编写真值表来解决。!
表示逻辑否定或不,或者您甚至可以将其视为相反。就我个人而言,我发现它对建立特定真值表的所有部分。
a | b |!b | a& b | a&! b | !(a& b)
-------------------------------------------- --------------------------------------------
A = 60 | B = 40 | !(B = 40)| (A = 60& B = 40)| A = 60& !(B = 40)| !(A = 60& B = 40)
T | T | F | T | F | F
T | F | T | F | T | T
F | T | F | F | F | T
F | F | T | F | F | T
您应该注意您的特定示例受
P是A = 60
Q是B = 40 $ b $b¬是! $ b $b∧是&& $ b $b∨是||
so ...
!(A&& B)
与真的相同!A || !B
真值表告诉您解决该问题需要了解的其余部分。
I have a question for an assignment. The questions is basically the following:There are 2 integer variables say A and B. Both these integers contain data.Using a truth table, which, if any, of the following IF statement tests is equivalent to:
if (!(A == 60 && B == 40))
- if (A != 60 || B != 40)
- if (A == 60 && (!(B == 40)))
How would i tackle this please. Anything advice would be appreciated. I think that I have to create a table with three columns - one called A, another B, and the third column called RESULT (YES OR NO).
The statement: if (!(A == 60 && B == 40))
- I am not to sure how to read the part if (!
. In other words, the part A == 60 && B == 40
is telling me essentially that A must equal 60 AND AT THE SAME TIME B must equal 40. Following that I am confused. Any help/advise please would be appreciated.
ThanksChris
This really has nothing to do with Java per se. Yes, you can solve by writing the truth tables. The !
means logical negation or not or you may even think of it as opposite. Personally, I find it helpful to establish all the parts of a particular truth table.
a | b | !b | a & b | a & !b | !(a & b)
----------------------------------------------------------------------------------------
A = 60 | B = 40 | !(B = 40) | (A = 60 & B = 40) | A = 60 & !(B = 40) | !(A = 60 & B = 40)
T | T | F | T | F | F
T | F | T | F | T | T
F | T | F | F | F | T
F | F | T | F | F | T
You should note your particular example is subject to one of De Morgan's Laws.
P is A = 60
Q is B = 40
¬ is !
∧ is &&
∨ is ||
so...
!(A && B)
is really the same as !A || !B
The truth table tells you the rest you need to know to solve that problem.
这篇关于真相表 - 援助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!