• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jwhiz, Logical OR on int. What?

 
Mike Kelly
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jwhiz exam#6 quest10 says this code compiles correctly, but I thought logical OR could not be done on int types, only booleans?
Any help?
(please excuse the OR operator)
int i = 1;
int j = 2;
if(i == 1 ll j == 2)
{
System.out.println("Ok");
}
 
Mariusz Szurnacki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look:
1. comparison operators � all return boolean type
2. comparison operators have higher priority than logical OR
So, in this case, you "have" the following statement:
if((i == 1) ll (j == 2))
Have a nice day,
Mariusz
 
Mike Kelly
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh yes, Thank-you Mariusz. Precedence of operators and operations, I have it right here in my notes. I've got the concept now, thanks.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!