Page 148 - Cs_withBlue_J_C11_Flipbook
P. 148
Let us see all the different types of shorthand operators.
Operator Meaning Description Example Equivalent Arithmetic
Expression
+= Addition Assignment It is used to add the value of the c += 1 c = c + 1
right operand to the variable and
assign the result to the variable.
-= Subtraction Assignment It is used to subtract the value d -= 5 d = d - 5
of the right operand from the
variable and assign the result to
the variable.
*= Multiplication Assignment It is used to multiply the variable by m *= b m = m * b
the value of the right operand and
assign the result to the variable.
/= Division Assignment It is used to divide the variable by div /= 4 div = div / 4
the value of the right operand and
assign the result to the variable.
%= Remainder Assignment It is used to divide the variable rem %= 5 rem = rem % 5
by the value of the right operand
and assign the remainder to the
variable.
Relational Operators
A relational operator is used to compare two variables or expressions and result in true or false. There are six types of
relational operators. 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
Let us see the following programming code:
class program_relational_operator
{
public static void main()
{
int m=20, n=5;
System.out.println("The value of m is " +m+ " n is " +n);
System.out.println("== operator : " +(m==n));
System.out.println("!= operator : " +(m!=n));
System.out.println("> operator : " +(m>n));
System.out.println("< operator : " +(m<n));
System.out.println(">= operator : " +(m>=n));
System.out.println("<= operator : " +(m<=n));
}
}
146146 Touchpad Computer Science-XI

