Page 135 - computer science (868) class 11
P. 135

c  =  a-- / --a * b++ + --b;
                      =  20/18 * 40 + 40
                      =  1 * 40 + 40
                      =  40 + 40
                      =  80

                 3.  if int m=40, n=22;
                   m  += m + m--/--m + n;                      [use of shorthand operator]
                   m  =  m+ (m + m--/--m + n)
                      =  40 + (40+40/38 + 22)
                      =  40 + (40 + 1 + 22)
                      =  40 + (63)
                      =  103
                 4.  if int a=2, b=3, c=0;
                   c  -=  ++a + (b++ % c);
                   c  =  c - (++a + (b++ % c))
                      =  0 - (3 + (3 % 0))                     [Error: java.lang.ArithmeticException: / by zero]

                 Ternary Operator:
                 1.  int a=40, b=35, c;
                   c  =  (a==b) ? a*b : a-b;
                      =  (40==35) ? 40*35 : 40-35
                      =  5

                 2.  boolean isLeapYear = true;
                   int febDays  =   isLeapYear? 29 : 28;
                              =  29
                 3.  String result=(num%2 == 0)? "Even": "Odd";
                   System.out.println(result);
                   What will be the result if num is 40?
                   Output: Even
                 4.  int a=10, b=20, c=15;
                   System.out.println(((a+b)>c)? a+b : b-c);
                   Output: 30                                  [working: ((30>15)? 30: 5)]
                 Relational Operator and Logical Operator:
                 double m=100, n=200, p=30;
                   1.  m<=n;
                       100<=200
                 Ans.  true

                   2.  m==n;
                       100 == 200
                 Ans.  false

                   3.  (m>n) && (m==n);
                       (100>200) && (100==200)
                       false&&false
                 Ans.  false
                   4.  !(n>m) || (m>n);
                        !(200>100) || (100>200)


                                                                                                                       133
                                                                                               Variables and Expressions  133
   130   131   132   133   134   135   136   137   138   139   140