TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java

Java Relational Operators

Overview

Java relational operators are symbols that are used to compare the operands. The operators are binary and require two operands to perform the calculations.

Relational Operators

Java relational operators are shown below:

Relational Operation
Operator Symbol Example
Equal To

 

==a == b
Not equal to!=a != b
Greater Than>a > b
Greater Than or Equal To>=a >= b
Less Than<a < b
Less Than or Equal To<=a <= b

 

Example

Let’s look at an example of Relation operator in a sample program. We will declare two variables of type int. We will compare if a is less than b in a if statement. If a < b then the expression evaluates to true.

 

public class RelationalOperatorDemo {

 public static void main(String[] args) {
 int a = 10;
 int b = 20;
 if( a < b) // Relational Operator
 System.out.println("a is less than b");
 else if(a == b)
 System.out.println("a is equal to b");
 else
 System.out.println("a is greater than b");
 }
}

 

 

Based on the values, a variable holds the value of 10 and b variable holds the value of 20. Since, 10 < 20 the expression a < b evaluates to true. The if statement would be executed and the else statements will not execute.

 

Java Relational Operator

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Download Greenfoot Windows

Java /

Download & Install Greenfoot on Windows

Java /

Java Static Code Analysis

Java /

Java Testing Tools

Java /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java /

Exceptions in Java Programs

‹ Java Arrays› Java Conditional Operators

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Print Triangle Pattern Flowchart
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version