Page 190 - CA_Blue( J )_Class10
P. 190

14.  What is the difference between a break statement and a continue statement when they occur in a loop?   [2013]
                 Ans.
                                    break Statement                                 continue Statement
                     Used to exit from a loop.                    Used to go to the next iteration in the loop.
                     for(i=1; i<=5; i++)                          for(i=1; i<=5; i++)
                     {                                            {
                     if(i%2==0)                                   if(i%2==0)
                          break;                                       continue;
                     System.out.print(i);                         System.out.print(i+ " " );
                     }                                            }
                     Output will be: 1                            Output will be: 1 3 5

                 15.  How many times will the following loop execute? What value will be returned?
                    int x = 2, y = 50;
                    do{
                        ++x;
                        y -= x++;
                    }while(x <= 10);
                    return y;                                                                                     [2013]
                Ans.  The loop will execute for 5 times.
                    15 will be returned
                 16.  Rewrite the following program segment using while instead of for statement.
                    int f = 1, i;
                    for(i = 1; i <= 5; i++){
                        f *= i;
                        System.out.println(f);
                    }                                                                                             [2012]
                Ans. int f = 1, i = 1;
                    while(i <= 5){
                       f *= i;
                       System.out.println(f);
                       i++;
                    }
                                                            SECTION B

                 17.  Using the switch-case statement, write a menu-driven program to do the following:
                     a) To generate and print Letters from A to Z and their Unicode letter.
                        Letters   Unicode
                          A        65
                          B        66
                           .        .
                           .        .
                          Z        90

                    b) Display the following pattern using the iteration (looping) statement:
                          1
                          1 2
                          1 2 3
                          1 2 3 4
                          1 2 3 4 5                                                                               [2019]

                Ans.  import java.util.*;
                    class question5
                    {
                        public static void main()




                188188  Touchpad Computer Applications-X
   185   186   187   188   189   190   191   192   193   194   195