Page 141 - CA_Blue( J )_Class10
P. 141

14.  What will be the output of the following code snippet?
                       int x = 30;
                       if (x < 20)
                       {   if (x < 10)
                           {        System.out.println("Less than 10");    }
                           else
                           {        System.out.println("Between 10 and 20");     }
                       }
                           else
                       {   System.out.println("20 or more");    }
                       a.  Less than 10                                b.  Between 10 and 20
                       c.  20 or more                                  d.  No output
                   15.  What will be the output of the following code snippet?
                       int score = 2;
                       switch (score) {
                           case 1:
                               System.out.println("Score is 1");
                           case 2:
                               System.out.println("Score is 2");
                           case 3:
                               System.out.println("Score is 3");
                               break;
                           default:
                               System.out.println("Default case");
                       }
                       a.  Score is 1                                  b.  Score is 2
                       c.  Score is 3                                  d.  Score is 2 and score is 3
                   16.  Which of the following boolean expressions will execute the if block?
                       int x = 5, y = 10;

                       if ( /* boolean expression */ ) {
                           System.out.println("Condition met");
                       }
                       a.  x > y                                       b.  x == y
                       c.  x < y                                       d.  x >= y
                   17.  What is the result of the following code?
                       int a = 5, b = 10;
                       String result = (a > b) ? "a is greater" : "b is greater";
                       System.out.println(result);
                       a.  a is greater                                b.  b is greater
                       c.  true                                        d.  false
                   18.  What will be the output of the following code snippet?
                       int x = 5, y = 15;
                       if (x > 3 && y < 20)
                       {    System.out.println("Condition met");    }
                       else
                       {    System.out.println("Condition not met");    }
                       a.  Condition met                               b.  Condition not met
                       c.  Compilation error                           d.  Runtime error




                                                                                                                       139
                                                                                           Conditional Constructs in Java  139
   136   137   138   139   140   141   142   143   144   145   146