Page 263 - CA_Blue( J )_Class9
P. 263

3.   Placing the ………………… statement in correct position will allow the control execute the next iteration of inner loop or
                        outer loop.
                    4.   If an outer loop runs four times and an inner loop runs three times for each iteration of the outer loop, the inner loop
                        will run a total of ………………… times.

                    5.   Patterns in programming can be generated using ………………….

                  Answers
                  1. jump            2. outer           3. continue         4. 12             5. nested loops


                 C.  Answer the following questions.
                    1.  What will be the output of this program?

                     class for_practice
                     {
                         public static void main(String s[])
                         {
                             int sum = 0,i,j;
                                                                                   i  j  sum=0              output
                             for( i = 1; i <= 2; i++ )
                                                                                   1  2  2
                             {
                                                                                       3  5
                                 for( j = 2; j <= 4; j++ )
                                                                                       4  9
                                 {
                                                                                   2  2  13
                                     sum += ( i * j);
                                                                                       3  19
                                 }
                                                                                       4  27          27
                             }
                             System.out.println("Result = " + sum);
                         }
                     }
                   Ans.  Result = 27
                    2.  Find the error.
                      int a;
                            while(a<=10)
                            {     int b=2;
                                  while(b<=4)

                                  {    b++;
                                  }
                            }
                   Ans.  There are two mistakes:
                      1.   variable “a” is not initialised
                      2.   no increment for variable “a”

                    3.  Analyse the given program segment and answer the following questions:
                     for(int i = 3; i <= 4; i++){
                        for(int j = 2; j <i; j++){
                           System.out.print("");
                        }
                       System.out.println("WIN");
                     }
                      a.   How many times does the inner loop execute?




                                                                                                   Nested Loop   261
   258   259   260   261   262   263   264   265   266   267   268