India's Largest Free Online Education Platform

Relational operator in java

Relational operator in java

Code:

import java.util.Scanner;
public class Relational_Operator {
    public static void main(String args[]) {
        System.out.println("Enter two numbers to permorm relational operators such as !=,==,>,<,>=,<=");
        Scanner Sc = new Scanner(System.in);
        int a = Sc.nextInt();
        int b = Sc.nextInt();
        if (a != b)
            System.out.println(" a and b are not equal // '!=' tested // instructions under if(a==b) will not execute ");
        if (a == b)
            System.out.println(" a and b are  equal // '==' tested // instructions under if(a!=b) will not execute");
        if (a > b)
            System.out.println(" a is greater than b  // '>' tested // instructions under if(a<b) will not execute" );
        if(a<b)
            System.out.println(" a is smaller than b // '<' tested // instructions under if(a>b) will not execute");
        if (a >= b)
            System.out.println(" a is greater or equal to b  // '>=' tested");
        if(a<=b)
            System.out.println(" a is smaller or equal to  b // '<=' tested");
    }
}

Output:01

Output:02

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!