Page 233 - IT-802_class_12
P. 233

To print char or String variables, we can use the System.out.println() method.

            System.out.println(first_name+” “+ middle_name+” “+last_name);
            The output from the statement given above is:

            Mayank M Saxena
            Note the use of the + operator. In Java, when used with numbers as operands, the + operator adds the numbers. When
            used with Strings as operands, the + operator concatenates the strings together. Also, note that the single space String
            literal (“ “) is used so as to print a gap between the first and middle name and middle and last name.
              3.3 oPEratorS

            Operators are special symbols that execute specific operations in a programming language. The operators * and / have
            already been observed. Java provides many types of operators some of them are:
            Ð ÐArithmetic operators

            Ð ÐRelational operators
            Ð ÐAssignment operators
            Ð ÐLogical operators
            3.3.1 Arithmetic Operators

            An arithmetic operator is used for writing codes that perform arithmetical calculations. The assignment operators are
            discussed in the table given below:

                                                                               Example (int a = 20,
                Operator      Description               Explanation                                     Result
                                                                                     b = 30)
                                             Returns  the  sum  of  values  of
                    +       Addition                                                  a+b                50
                                             operands
                                             Returns  the  difference  of  values  of
                    -       Subtraction                                                a-b               -10
                                             operands
                                             Returns  the  product  of  values  of
                    *       Multiplication                                            a*b                600
                                             operands
                                             Returns  the  quotient  of  division  of
                    /       Division                                                   b/a                1
                                             values of operands
                                             Returns the remainder of division of
                   %        Modulus                                                   a%b                10
                                             values of operands
                   ++       Increment        Increments the operand by 1           a++ Or ++a            21
                    --      Decrement        Decrements the operand by 1            a-- Or --a           29

            3.3.2 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         Description                 Explanation                Example          Result
                                                 Returns true if values of a and b are
                  ==       Equal to                                                      a==b            false
                                                 equal, false otherwise
                                                 Returns true if values of a and b are
                   !=      Not equal to                                                  a!=b            true
                                                 not equal, false otherwise



                                                                               Fundamentals of Java Programming  231
   228   229   230   231   232   233   234   235   236   237   238