Page 170 - Computer science 868 Class 12
P. 170

II.  Ternary Operator
                 1.  int a = 10, b = 20, c;

                   c = (a>b)? a : b;
                     = (10>20)? 10 : 20
                     = 20
                 2.  int n1 = 2, n2 = 9, n3 = -11, highest;
                  highest = (n1 >= n2)? ((n1 >= n3)? n1 : n3) : ((n2 >= n3)? n2 : n3);

                 System.out.println("Highest Number :  " + highest);
               Ans. Highest Number : 9
                 3.  int marks = 56;

                   String status = marks>=35 ? "You are Passed" : "You are failed";
                   System.out.println("Status = " + status);
                 Ans.  Status = You are Passed

              III. Relational and Logical Operators
                 1.  int a = 10, b = 2, c = 15, d;
                    a.  (a>b) || (b==c)     = (10>2) || (2==15)        = true||false  =  true
                    b.  ((a+b)>c) || (a>c)   = (12>15) || (10>15)      = false|| false  =  false
                    c.  (a>b) && (b==c)     = (10>2) && (2==15)        = true&&false  =  false
                    d.  ((a+b)>c) && (a>c)   = (12>15) && (10>15)      = false&&false   =  false


                 2.  int a = 10, b = 20;

                      System.out.println(a > 5 && a < 20 && b > 15);
                Ans.  true



                             Let’s Revisit


                     ♦ Different sets of characters used in Java Language are: alphabets, digits, operators and delimiters.
                     ♦ Each individual character that is used for creating an executable code in Java is known as a token.

                     ♦ The different types of tokens in Java are as follows:
                   *  Literals                              *  Identifiers
                   *  Operators                             *  Assignments
                   *  Keywords                              *  Special Symbols such as punctuators and separators.
                     ♦  Literals are the constant values used in a program code.

                     ♦  Identifiers are used to give names to variables, classes, methods, etc.
                     ♦  Variables are the named memory locations that contain values depending on the type of the variable. Syntax to declare a
                   variable is:

                   <data type> <space><name of the variable> [= <value>];
                   where [= <value>] is optional.
                     ♦ The keyword ‘final’ is used to make the variable fixed which can’t change its values. The syntax for using the keyword final is
                   <final> <datatype> <name_of_variable> = value.
                     ♦ Operators are used to instruct the compiler to execute some operations or calculations.






                168168  Touchpad Computer Science-XII
   165   166   167   168   169   170   171   172   173   174   175