Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 96 - 2617_JSSPS_C-7
P. 96

    EXPRESSIONS

                  An expression has two parts: Operand and Operator. The variables or values that are used in the
                  expression are called Operand and the symbols on which the operand works such as + (addition), –
                  (subtraction), etc. are known as Operators. For example:

                                                                  c = a + b;

                  Here, a and b are operands and + is the operator.

                  Operators

                  Java usually has a group of built-in operators with common meaning assigned to them, though in some
                  special cases it allows programmers to assign different meanings. Let us understand with an example:

                                                 double m=34.76, n= 3.6, r;

                                                 int a = 1, b = 4, c;

                                                 r = m * n;
                                                 c = b - a;

                                                 System.out.println(“The product is:” +r);

                                                 System.out.println(“The difference is:” +c);

                  Explanation of code: In each line, we are using different types of operators and related operands.

                  In the 1st line:
                     “=” acts as an assignment operator and “m”, “n”, 34.76 and 3.6 are variables and constants.

                  Similarly in the 2nd line:

                     “=” acts as an assignment operator and “a”, “b”, 1 and 4 are variables and constants.
                  In the 3rd line:

                     “=” and “*” acts as an assignment operator and binary operator respectively and “m”, “n” and “r”
                     are operands.

                  In the 4th line:

                     “=” and “-” acts as an assignment operator and binary operator respectively and “a”, “b” and “c” are
                     operands.
                  In the above example, m*n and b-a are Arithmetic Expression and r = m*n and c = b-a is said to be
                  Arithmetic Statement.

                  Arithmetic Expression:  Any  meaningful  expression  containing  identifiers,  literals and  arithmetical
                  operators and producing a result is called an Arithmetic Expression.

                  Example: a*b, 2*(l + b)

                            Premium Edition-VII
                     94

| 91 92 93 94 95 96 97 98 99 100 101 |