Java Operators - Relational Operators


Relational Operators are also known as comparison operators.

They are used to compare two values and return a boolean result.

Here are the list of relational operators;

Java Operator Mathematical Symbol Name Example (diameter = 10) Result
< < less than diameter < 0 false
<= less than or equal to diameter <= 0 false
> > greater than diameter > 0 true
>= greater than or equal to diameter >= 0 true
== = equal to diameter == 0 false
!= not equal to diameter != 0 true

NOTE: To test equality you use two equal signs(++), not a singke equal sign(=). The latter is used for assignment.

The result from a comparison is either true or false.

Example:

package info.tutorialsloop;

public class Main {

    public static void main(String[] args) {

        double diameter=19.5;
        System.out.println(diameter > 0);
        System.out.println(diameter < 0);
        System.out.println(diameter >= 0);
        System.out.println(diameter <= 0);
        System.out.println(diameter == 0);
        System.out.println(diameter != 0);
    }
}

RESULT

true
false
true
false
false
true

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post