Menu
Topics Index
...
`

Print number relations - Java Example Program


Print number relations
class PrintNumberRelations
{
    public static void main(String arg[])
    {
        int a = 4;
        int b = 1;
        boolean x = ( a > b );
        boolean y = ( a <= b );
        boolean z = ( a == b );
        
        System.out.println(" The statement - a greater than b - is " + x);
        System.out.println(" The statement - a is less than or equal to b - is " + y);
        System.out.println(" The statement - a is equal to b - is " + z);    
    }
}
OUTPUT

The statement - a greater than b - is true
The statement - a is less than or equal to b - is false
The statement - a is equal to b - is false

DESCRIPTION

Here the relation between a and b is found using various relational operators. x tells if a is greater than b (a > b), y tells if a is less than or equal to b (a <= b) and z tells if a and b are equal (a == b).

THINGS TO TRY
  • Add a new boolean w which tells if a greater than or equal to b and print the result.
  • Add a new boolean v which tells if a is not equal to b and print the result.
  • Add a new boolean u which tells if ((a + 2) * 3) is less than ((b + 1) * 9) and print the result.

© meritcampus 2019

All Rights Reserved.

Open In App