Java logical operators example.

Java logical operators example.


Posted in : Core Java Posted on : October 9, 2010 at 5:49 PM Comments : [ 0 ]

In this section, you will see the use of logical operatoer in java.

Java logical operators example.

Relational operator is used for single condition check. If you want to check multiple condition. Than you requires logical operator. These logical operator are && logical And, || logical OR and ! Logical Not. It returns only  boolean value.

Code:

LogicalOperator.java
package com.devmanuals;

public class LogicalOperator {
	int a = 10, b = 10, c = 10;
	boolean bool = false, bool1 = true;

	public void logicalAND() {
		if ((a == b) && (a == c)) {
			System.out.println("a is equal to b and c.");
		} else {
			System.out.println("a is not equal to b and c.");
		}
	}
	public void logicalOR() {
		System.out.println("bool || bool1 : " + (bool || bool1));
	}
	public void logicalNot() {
		System.out.println("bool1!= true : " + (bool1 != true));
	}
	public static void main(String[] args) {
		LogicalOperator obLogicalOperator = new LogicalOperator();
		obLogicalOperator.logicalAND();
		obLogicalOperator.logicalOR();
		obLogicalOperator.logicalNot();
	}
}
Output:
a is equal to b and c.
bool || bool1 : true
bool1!= true : false

Download this code.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics