posted 14 years ago

In the statement below given values for x and y

if ( (x>3) && (y>2) | dostuff() ) {}

is the same as

( (x>3) && ((y>2)| dostuff()) )

because | has higher precedence over &&

what if I have the statement

( (x>3) & (y>2) | dostuff() ) {}

In what order will it be evaluated?

Thanks,

vijaya

if ( (x>3) && (y>2) | dostuff() ) {}

is the same as

( (x>3) && ((y>2)| dostuff()) )

because | has higher precedence over &&

what if I have the statement

( (x>3) & (y>2) | dostuff() ) {}

In what order will it be evaluated?

Thanks,

vijaya

SCJP 1.4

posted 14 years ago

A search on google referred me to this page with the order of operations:

http://www.sniffer.net/bookshelf_do_sniffer/java/langref/ch04_14.htm

The & is higher in terms of precedence so the statement would be executed from left to right as is

http://www.sniffer.net/bookshelf_do_sniffer/java/langref/ch04_14.htm

The & is higher in terms of precedence so the statement would be executed from left to right as is

posted 14 years ago

( (x>3) & (y>2) | dostuff() ) {}

I think since its always from left to right the and is first evaluated then

I think since its always from left to right the and is first evaluated then