Free Web Tutorials Free Online Tutorials About Us Contact Us

Java Operators Tutorial.


2. Java Comparison Operators


Comparison operators are used in logical statements to determine equality or difference between variables or values.

Operators

Description

==

Equal to

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

!=

Not equal to


Comparison operators (can be known as Relational operators) can be used in conditional statements to compare values and take action depending on the result:

Examples:


public class checkComparisonOperators{
	public static void main(String[] args) {
	
	int numA = 5;
	int numB = 3;
	
	if(numA >= numB){
		System.out.println("numA is greater than numB");
	}else{
		System.out.println("numA is not greater than 		numB");
	}

}


The output from the above examples would be:

	numA is greater than numB.

free online java tutorial free online java tutorial