Page 264 - CA_Blue( J )_Class9
P. 264

b.   Write the output of the program segment.
                    Ans.  a.  Loop executes for 2 times
                       b.   WIN
                          WIN
                     4.  Find the error.
                       class do_while_output
                       {   public static void main()
                         {   int i,j;
                                do

                                {   j=i;
                                 do
                                     System.out.println("i = " + i + " j = " + j);
                                         j++;
                                     }while(j<=5)
                                i++;
                                }while(i<=5);
                         }
                       }
                    Ans.  There are 3 mistakes
                       1.  Variable “i” is not initialised
                       2.  After inner “do” there will be an open brace “{“
                       3.  There will be a semicolon “;” after inner while
                     5.  What will be the output? How many times the loop will execute?
                       int i,j;
                       for (i=1; i<=3; i=i+1)
                       {for (j=2; j>=1; j--)
                       {System.out.print ((i+j)+ “ : ”) ;}
                       }
                    Ans.  3:2:4:3:5:4:
                       The loop executes 6 times.


                       Unsolved Questions



                  A.  Tick ( ) the correct answer.
                     1.   In a nested do-while loop, what happens if the inner loop evaluates to false on the first step?
                         a.  Run time error                             b.  The outer loop executes once
                         c.   The inner loop executes once              d.  Both b and c
                     2.   While loops are nested. Which loop needs to end abruptly for the entire construct to shut down.
                         a.  The first outer loop                       b.  The middle loop
                         c.   The innermost loop                        d.  None of these
                     3.   What is the output of the following code
                         class NestedFor
                         {



                   262    Touchpad Computer Applications-IX
   259   260   261   262   263   264   265   266   267   268   269