Page 231 - CA_Blue( J )_Class9
P. 231

System.out.println(i);
                            }
                        a.  8                                          b.  4
                        c.   9                                         d.  0

                  Answers
                  1. a     2. b    3. b     4. d    5. a     6. a    7. c     8. b     9. c     10. c

                 B.  Fill in the blanks.
                    1.   int i = 2;
                        while(i<=10)
                        {
                            i=i+2;
                        }
                        The value of i is ………………… after the execution of the loop.
                    2.   ………………… is  an exit control loop.
                    3.   ………………… executes the statements in the loop body a fixed number of times.
                    4.   In a loop, ………………… is used to exit from the loop.
                    5.   To find the sum of any five numbers, the loop will run ………………… times.
                    6.   Iteration means ………………… of statements.
                    7.   char ch= "y";

                            for(;ch== "y";)
                            {     ch = "n";
                                  System.out.println(ch);
                            }
                        The final value of ch is …………………;
                    8.   A ………………… statement is used to stop the sequential flow of statements and continues to the next iteration.
                    9.   ………………… statement takes the control back to the caller module from the method.
                    10.   The do-while loop will execute ………………… even if the test condition is false.

                  Answers
                  1. 12         2. do-while     3. finite loop    4. break    5. Exit Control Loop    6. repetition
                  7. n          8. continue     9. return      10. once


                 C.  Answer the following questions.

                    1.   Convert the while loop to a for loop.
                     int i=1;
                     while(i<=10)
                     {      System.out.println(i);
                            i=i+1;
                     }
                   Ans.  for(int i=1;i<=10;i=i+1)
                     {      System.out.println(i);      }
                                                                                                    i       Output
                    2.  Write the output of the below Java program?
                                                                                                    1       2 4
                     int i=1;
                                                                                                    3
                     for(;i<5;i++)
                                                                                                    5<5 X
                     {      System.out.print(++i);      }
                   Ans.  24

                                                                                       Iterative Constructs in Java  229
   226   227   228   229   230   231   232   233   234   235   236