Java-operators
Equality and Relational Operator
Operator Meaning Example
== equals 5==5
!= not euals to 5!=5
>= greater than equal 5>=3
< = Less than equal 5<=3
instanceof datatype comparision
example:
Ternary operator:
variableName = expression ? value1 : value2;
if expression is true ,Value1 is assigned
if expression is false ,Value2 is assigned
Example:
damageText=isDamaged?"This car is damaged":"This car is not damaged"
Logical Operators:
Operator Meaning Example
|| OR -true , if either of the boolean exp is true false||true- equals true
&& AND- true if all boolean exp is true False&& true -equals false
Assignment Operators:
Operator Meaning example
= assign value to a variable int price= 5
+= add and equals price+=5 equals 10(can replace this price=price+5)
-= substract and equals price-=5 equals 0(Can replace this price=price-5)
*= multiply and equals price*=3 equals 15(Can replace this price=price*3)
/= divide and equals price/=3 equals 1(Can replace this price=price/3)
%= reminder and equals price%=3 equals 2(Can replace this price=price%3)
Comments
Post a Comment