Page 162 - ComputerScience_Class_11
P. 162
They are as follows:
Operator Meaning Example: int a=10, b=2 Result
> Greater than a>b True
>= Greater than or Equal to a>=b True
< Less than a<b False
<= Less than or Equal to a<=b False
== Equal to a==b False
!= Not Equal to a!=b True
Program 3 Write a program that compares two integers using relational operators and prints the results.
1 class program_relational_operator
2 {
3 public static void main(String[] args)
4 {
5 int m=20, n=5;
6 System.out.println("The value of m is " +m+ " and n is " +n);
7 System.out.println("== operator : " +(m==n));
8 System.out.println("!= operator : " +(m!=n));
9 System.out.println("> operator : " +(m>n));
10
System.out.println("< operator : " +(m<n));
11 System.out.println(">= operator : " +(m>=n));
12 System.out.println("<= operator : " +(m<=n));
13 }
14 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
The value of m is 20 and n is 5
== operator : false
!= operator : true
> operator : true
< operator : false
>= operator : true
<= operator : false
Logical Operators
A logical operator is used to check whether an expression results in true or false. There are three types of logical
operators.
160 Touchpad Computer Science (Ver. 3.0)-XI

