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

}
                         else
                         {
                           if(y<z)
                           {
                            System.out.println(z);
                           }
                           else
                           {
                            System.out.println(y);
                           }
                         }
                   Ans.  10
                        ii.   int var = 2;
                         switch(var) {
                         case 1:
                         System.out.println("good");
                         break;
                         case 2:
                         System.out.println("better");
                         case 3:
                         System.out.println("best");
                         default:
                         System.out.println("invalid");
                         }
                   Ans.  better
                        best
                        invalid
                    10.  Rewrite the following code after corrections.
                        i.   int a;
                         if(a=1)
                          a==100;
                         else If(a=2)
                          a=1000;
                   Ans.  int a;
                       if(a==1)
                         a=100;
                       else if(a==2)
                         a=1000;
                        ii.   switch(m){
                         case 0:
                          x=x+2;
                          System.out.println("X=" x);
                          break;
                         case 1:
                          x=x+4;
                          System.out.println("X=" x);
                          break;
                         case 2:
                          x=x+6;
                          System.out.println("X=" x);
                          break; }


                                                                                                                       183
                                                                                                 Statements and Scope  183
   180   181   182   183   184   185   186   187   188   189   190