• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Boolean Operator

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

What is the diffrence between "!=" and "=!" operartor.
As per me this operartor can only be applied on boolean first of all.
Also if

b1 != b2; //line 1
here , its doing comparison between b1 and b2.
If they are not equal to each other then line 1 return true otherwise false.

b1 =! b2; // line 2
Here its doing assignment b2 to b1.
That is if b2 is "false" then due to (!b2) true is going to get assign to b1.

Am I right?

***************************************************************************

One more thing I want to ask-

boolean b1=false;
boolean b2=false;

b2!=b1!=b2; //Line 1
b2!=b1=!b2; //Line 2

Are these 2 lines going to compile and run?
For me its giving error stating "Invalid statement".
Also I am confused.
Please help me out with the above two.

Thanks
[ March 09, 2008: Message edited by: sandhi mridul ]
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What is the diffrence between "!=" and "=!" operartor.


The second is not an operator but rather two operators '=' and '!'.
For better readability try: b1 = !b2;
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sandhi mridul:
Hi,

What is the diffrence between "!=" and "=!" operartor.
As per me this operartor can only be applied on boolean first of all.
Also if

b1 != b2; //line 1
here , its doing comparison between b1 and b2.
If they are not equal to each other then line 1 return true otherwise false.

b1 =! b2; // line 2
Here its doing assignment b2 to b1.
That is if b2 is "false" then due to (!b2) true is going to get assign to b1.

Am I right?

***************************************************************************

One more thing I want to ask-

boolean b1=false;
boolean b2=false;

b2!=b1!=b2; //Line 1
b2!=b1=!b2; //Line 2

Are these 2 lines going to compile and run?
For me its giving error stating "Invalid statement".
Also I am confused.
Please help me out with the above two.

Thanks

[ March 09, 2008: Message edited by: sandhi mridul ]





Hi Sandhi,
what you said is rite.
is comparision and
is Assigment
Instead of this
you can use as


moreover,i dont know why the following check needed
its enough to have as

you may try down as

 
sandhi mridul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Hamsagayathri.
But still not sure if line 1 and 2 going to compile or not.
I found these in 2 diffrent mock test with diffrent answers.
I tried but giving Compiler error.
So just need to conform.

boolean b1=false;
boolean b2=false;

b2!=b1!=b2; //Line 1
b2!=b1=!b2; //Line 2
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic