Page 58 - CA_Blue( J )_Class10
P. 58

Arithmetical Statement:  When an expression is assigned to a variable, then it is called an arithmetical statement. For
              example: c = a * b and p = 2 * (l + b).
              Conversion of Mathematical Expression to Java Expression

                                 Mathematical Expression                          Java Expression
                       ab+bc+ca                                    a*b+b*c+c*a
                       2πr 2                                       2*22.0/7.0*r*r
                             r                                     p*Math.pow((1+r/100.0),n)-p
                                 n
                       p(1+     )  - p
                            100
                       a  + b  + c  + 2ab + 2ac + 2bc              a*a +b*b + c*c + 2*a*b + 2*a*c + 2*b*c
                        2
                            2
                                2
                       ad + bc                                     (a*d+b*c)/(b*d)
                         bd
                         3                                         Math.sqrt(3)/4.0 * side * side
                         4   × side2
              Let us study the different forms of operators in detail.


                   4.2 FORMS OF OPERATORS
              There are mainly three forms of operators in Java:
              •  Unary Operator: An operator that works with only one operand is called a unary operator. Some of the unary
                 operators are a++ and b--. Where a and b are the operands, ++ and -- are the operators.
              •  Binary Operator: An operator that works with two operands is called a binary operator. Some of the binary operators
                 are a + b , a / b. Where a and b are the operands, + and / are the operators.
              •  Ternary Operator: An operator that works with three operands or expressions is called a ternary operator. It is also
                 called conditional operator because the value assigned to a variable depends upon a logical expression or a condition.
                Syntax:
                variable = Expression1 ? Expression2: Expression3
                Example:
                int fno = 20, sno = 10, max;
                max = (fno > sno) ? fno : sno;
                Program 1: To use all the three forms of operators in Java.






























                5656  Touchpad Computer Applications-X
   53   54   55   56   57   58   59   60   61   62   63