Eng.Fouad Eng.Fouad - 1 year ago 97
Java Question

!flag has two meanings in java?

boolean flag = false;
if(!flag) System.out.println(!flag); // prints true

I wonder why
being considered as
when it's a conditional parameter passed to
if statement
and as

Answer Source

It's not. if (boolean expression) { statement } means "execute the statement if boolean expression is true." Since flag = false, !flag == true. Always.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download