Java Program To Demonstrate Comparison Operators

Write Java program to demonstrate the use of comparison operators

// WAP to demonstrate comparison operator

public class ComparisonOperator
{
    public static void main(String[] args)
    {
        int a = 10,b = 8,c = 8;

        System.out.println("Value of a : "+a); 
        System.out.println("Value of b : "+b);
        System.out.println("Value of c : "+c);
     
        //Comparison operator return true ,if true; else return false

        System.out.println("\na == b : "+(a==b));
        System.out.println("a == c : "+(a==c));
        System.out.println("a > b : "+(a>b));
        System.out.println("a > c : "+(a>c));
        System.out.println("a < b : "+(a<b));
        System.out.println("a < c : "+(a<c));
        System.out.println("a != c : "+(a!=c));
        System.out.println("a != b : "+(a!=b));
        System.out.println("a >= b : "+(a>=b));
        System.out.println("a >= c : "+(a>=c));
        System.out.println("a <= b : "+(a<=b));
        System.out.println("a <= c : "+(a<=c));
    }
}

Output:


<< Previous | Next >>


Leave a Reply

Your email address will not be published.