Page 78 - CA_Blue( J )_Class10
P. 78

9.  What is the value of x1 if x = 5?
                    x1 = ++x - x++ + --x;                                                                         [2017]
                Ans.  = 6 - 6 + 6
                     = 0 + 6
                     = 6
                 10.  Write down Java expression for:
                           2
                                  2
                               2
                    T =   (A  + B  + C )                                                                          [2016]
                Ans.  T = Math.sqrt(A * A + B * B + C * C);
                 11.  Rewrite the following using ternary operator:
                    if(x % 2 == 0)
                          System.out.print("EVEN");
                    else
                          System.out.print("ODD");                                                                [2016]
                Ans.  System.out.print(((x % 2 == 0)? "EVEN":"ODD"));
                 12.  Give the output of the following expression:
                    a += a++ + ++a + --a + a--; when a = 7.                                                       [2016]
                Ans.  a  = a + a++ + ++a + --a + a--;
                      = 7 + 7 + 9 + 8 + 8
                      = 14 + 9 + 8 + 8
                      = 23 + 8 + 8
                      = 31 + 8
                      = 39
                 13.  Evaluate the value of n if value of p = 5, q = 19.
                     int n = (q - p) > (p - q)? (q - p) : (p - q);                                                [2015]
                Ans.  (19-5)>(5-19) = 14>-14 = true
                    n = 19 - 5 = 14.
                 14.  Write the Java expression for:
                         2
                     2
                     a + b + 2ab                                                                                  [2015]
                Ans.  (a * a + b * b) / (2 * a * b)
                 15.  If int y = 10 then find int z = (++y * (y++ + 5));                                          [2015]
                Ans.  z  = (11 * (11 + 5))
                      = 11 * 16
                      = 176
                 16.  Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators
                    given below in order of higher precedence to lower precedence.                                [2014]
                    a.  &&                                          b.  %
                    c.  >=                                          d.  ++
                Ans.  ++, %, >=, &&
                 17.  Give the output of the following method:
                    public static void main(String[] args)
                    {
                          int a = 5;
                          a++;
                          System.out.println(a);
                          a -= (a--) - (--a);
                          System.out.println(a);
                    }                                                                                             [2014]
                Ans.  6
                     4
                     [Explanation:   a++ = 6 as printing is done in next line.



                7676  Touchpad Computer Applications-X
   73   74   75   76   77   78   79   80   81   82   83