Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 97 - 2617_JSSPS_C-6
P. 97

    /** These types of comments are used when you want to add HTML code
                         into your Java program*/

                         }
                     }
                     When  you  run  the  preceding  code,  only  the  message "Comment Examples" will appear  on  the
                     terminal. All the comments are ignored by the compiler.

                     OPERATORS

                     An operator is a symbol that tells the compiler to perform specific mathematical or logical calculations.
                     It requires operands or values to perform calculations and returns the desired result.

                     For example:
                        int x = y + z;
                       or

                        int x = 10 + 20;
                     In  the  above  example,  the  plus  (+)  operator  is  used  to  calculate  the  sum  of  two  variables  (y  and  z)
                     or values (10 and 20). It calculates the sum and assigns the result to the variable x.

                     There are various types of operators in Java, which are as follows:
                        Arithmetic operators

                        Relational operators

                        Logical operators
                        Unary operators

                        Assignment operators

                     Let's discuss these in detail.

                     Arithmetic Operators

                     Arithmetic  operators are used  to  do  basic  mathematical calculations.  They  consist  of  both  unary
                     operators, which operate on a single operand, and binary operators, which require two operands.
                     These are as follows:
                                                                                               Example
                        Operator                    Description                  Syntax                        Output
                                                                                            (int a = 11, b = 4)
                            +         Returns the result after performing the     a + b          a + b            15
                         addition     addition operation.
                            –         Returns the result after performing the      a – b          a – b            7
                       subtraction    subtraction operation.
                            *         Returns the result after performing the     a * b          a * b             44
                      multiplication multiplication operation.
                            /         Returns the result after performing the      a / b          a / b            2
                         division     division operation.
                            %         Returns the remainder after performing      a % b          a % b             3
                        modulus       the division operation.

                                                                                  Introduction to Programming in Java   95

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