开发者

complex logical operation

开发者 https://www.devze.com 2023-03-28 04:36 出处:网络
Given this logical operation : (A AND B) OR (C AND D) Is there a way to write a开发者_JAVA百科 similar expression without using any parentheses and giving the same result ? Usage of logical operator

Given this logical operation :

(A AND B) OR (C AND D)

Is there a way to write a开发者_JAVA百科 similar expression without using any parentheses and giving the same result ? Usage of logical operators AND, OR, NOT are allowed.


Yes:

A and B or C and D

In most programming languages, and is taken to have higher precedence than or (this stems from the equivalence of and and or to * and +, respectively).

Of course, if your original expression had been:

(A or B) and (C or D)

you couldn't simply remove the parentheses. In this instance, you'd have to "multiply out" the factors:

A and C or B and C or A and D or B and D


How about A AND B OR C AND D? It's the same because AND takes precedence over OR.


Just don't put any parentheses, it is the same...


It can be written in two ways

  1. A & B | C & D
  2. Type as it is mentioned in question just remove the parenthesis it will show the same result.

We can use & for AND to multiply and | for OR to divide. Also simply you can write them without any parenthesis

0

精彩评论

暂无评论...
验证码 换一张
取 消