Velocity Reviews > Java > OR and AND without parenthesis

# OR and AND without parenthesis

IveCal
Guest
Posts: n/a

 06-22-2007
Hello, I have a question.
assuming, all letters below are either true or false.
Are the following the same:
1. (A OR B) && (C) && (D OR E OR F OR G OR H)
2. A OR B && C && D OR E OR F OR G OR H

John W. Kennedy
Guest
Posts: n/a

 06-22-2007
IveCal wrote:
> Hello, I have a question.
> assuming, all letters below are either true or false.
> Are the following the same:
> 1. (A OR B) && (C) && (D OR E OR F OR G OR H)
> 2. A OR B && C && D OR E OR F OR G OR H

There is no OR in Java. Assuming that you mean ||, no, they are not the same,
just as:

(a + b) * (c) * (d + e + f + g + h)

is not the same as:

a + b * c * d + e + f + g + h

--
John W. Kennedy
"Only an idiot fights a war on two fronts. Only the heir to the throne of the
kingdom of idiots would fight a war on twelve fronts"
-- J. Michael Straczynski. "Babylon 5", "Ceremonies of Light and Dark"

George N. Morcos
Guest
Posts: n/a

 06-22-2007
hi

the equation are not the same , they will generate different outputs
the execution sequence will be () --> and --> or

think of it as a numerical equation

On Jun 21, 10:39 pm, IveCal <(E-Mail Removed)> wrote:
> Hello, I have a question.
> assuming, all letters below are either true or false.
> Are the following the same:
> 1. (A OR B) && (C) && (D OR E OR F OR G OR H)
> 2. A OR B && C && D OR E OR F OR G OR H

Roedy Green
Guest
Posts: n/a

 06-22-2007
On Fri, 22 Jun 2007 02:39:50 -0000, IveCal <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>Hello, I have a question.
>assuming, all letters below are either true or false.
>Are the following the same:
>1. (A OR B) && (C) && (D OR E OR F OR G OR H)
>2. A OR B && C && D OR E OR F OR G OR H

There are three things you need to understand to solve problems of
this class:

1. the difference between the two flavours of or | and ||. see
http://mindprod.com/jgloss/boolean.html

2. the difference between the two flavours of or & and &&

3. the precedence table. See
http://mindprod.com/jgloss/precedence.html
--
The Java Glossary
http://mindprod.com

stefanomnn
Guest
Posts: n/a

 06-22-2007
> There is no OR in Java. Assuming that you mean ||, no, they are not the same,
> just as:
>
> (a + b) * (c) * (d + e + f + g + h)
>
> is not the same as:
>
> a + b * c * d + e + f + g + h
>
> --
> John W. Kennedy
> "Only an idiot fights a war on two fronts. Only the heir to the throne of the
> kingdom of idiots would fight a war on twelve fronts"
> -- J. Michael Straczynski. "Babylon 5", "Ceremonies of Light and Dark"

wonderful answare!