View RSS Feed

My Java Tips

Logical Operators

Rate this Entry
by , 10-30-2011 at 05:08 PM (435 Views)
Following are logical operators that one can use in Java programming.

! Is not…
^ Exclusive Or…
| Or… (bitwise)
& And… (bitwise)
|| Or… (short cut, see &&)
&& And


In this Java programming tutorial, I will code And, Or and Not operators as they are commonly used.

Example:
Java Code:
int a= 15;
int b = 25;
if(a<10 || b>10)
{
System.out.println("Entered: Java Programming Tutorial");
}
else
System.out.println("Not Entered: Java Programming Tutorial");
Output:

Entered: Java Programming Tutorial

In the given example, first condition is false as a is less than 10 but second condition is true as b is greater than 10. So if condition as a whole is true and we get the output:

Entered: Java Programming Tutorial

Submit "Logical Operators" to Facebook Submit "Logical Operators" to Digg Submit "Logical Operators" to del.icio.us Submit "Logical Operators" to StumbleUpon Submit "Logical Operators" to Google

Tags: None Add / Edit Tags
Categories
Java SE

Comments