Tutorials for Java ,Core java ,Advance java ,oracle ,HTML, CSS, JavaScript, Java and other programming language tutorial Learn Java tutorial for beginners with examples in eclipse online. Java tutorial point for core java, servlet, jsp, struts, spring, for learning web technologies online. Content includes tutorials and references relating to HTML, CSS, JavaScript, PHP, AngularJS, SQL, Bootstrap, Node.js, and jQuery this is a website like w3school tutorialspoint etc

Search This Blog

About

Header Ads

Friday, 1 June 2018

Comparison Operators in java

0 comments

Comparison Operators

Relational operators in Java are used to compare 2 or more objects. Java provides six relational operators:greater than (>), less than (<), greater than or equal (>=), less than or equal (<=), equal (==), and not equal (!=).

All relational operators are binary operators, and their operands are numeric expressions.
Binary numeric promotion is applied to the operands of these operators. The evaluation results in a boolean value. Relational operators have precedence lower than arithmetic operators, but higher than that of the assignment operators. An example program is shown below that demonstrates the different relational operators in java.
Ex:

public class RelationalOperatorsDemo {
 public RelationalOperatorsDemo( ) {
 int x = 10, y = 5;
 System.out.println(”x > y : “+(x > y));
 System.out.println(”x < y : “+(x < y));
 System.out.println(”x >= y : “+(x >= y));
 System.out.println(”x <= y : “+(x <= y));
 System.out.println(”x == y : “+(x == y));
 System.out.println(”x != y : “+(x != y));
 }

 public static void main(String args[]){
 new RelationalOperatorsDemo();
 }
 }
Logical operators return a true or false value based on the state of the Variables. There are six logical, or boolean, operators. They are AND, conditional AND, OR, conditional OR, exclusive OR, and NOT. Each argument to a logical operator must be a boolean data type, and the result is always a boolean data type. An example program is shown below that demonstrates the different Logical operators in java.

Ex:
public class LogicalOperatorsDemo {
public LogicalOperatorsDemo() {
boolean x = true;
boolean y = false;
System.out.println("x & y : " + (x & y));
System.out.println("x && y : " + (x && y));
System.out.println("x | y : " + (x | y));
System.out.println("x || y: " + (x || y));
System.out.println("x ^ y : " + (x ^ y));
System.out.println("!x : " + (!x));
}

public static void main(String args[]) {
new LogicalOperatorsDemo();
}
}




No comments:

Post a Comment