Page 217 - Computer science 868 Class 12
P. 217

9.  The following program prints the number is a palindrome or not. But there are some errors. Find the errors.
                       temp=121;
                           while(temp>0)
                          {
                               r=temp/10;
                             sum=(r*10)+sum;
                             temp=temp/10;
                          }
                               if(n==sum)
                                   System.out.println(n+" is not a palindromic number ");
                             else
                                   System.out.println(n+ " is a palindromic number");
                   Ans.  a. r=temp/10;      will be r=temp%10;
                        b. sum=(r*10)+sum;  will be sum=(sum*10)+r;
                        c. if(n==sum)       will be if(n!=sum)
                    10.  What type of loop is the following? What will be printed?
                       for(i=1; i>0; i++)
                       {
                           System.out.println(i);
                       }
                   Ans.  Infinite loop
                        The program will print all the natural numbers starting from 1.

                 D.  Assertion and Reasoning Based Question.
                    Assertion: In if-else, the flow of control is bidirectional.
                    Reason: In if else, the flow of control is depending on the choice of the user.
                    (a)  Both Assertion and Reason are true, and Reason is the correct explanation for Assertion.
                    (b)  Both Assertion and Reason are true, but Reason is not the correct explanation for Assertion.
                    (c)  Assertion is true and Reason is false.
                    (d)  Assertion is false and Reason is true.
                   Ans.  (c) In switch case, the flow of control is multidirectional, i.e., depending on the choice of the user.



                      Unsolved Questions



                 A.  Tick ( ) the correct option:
                    1.  What will be the output?
                         for(i=1; i<=5; i=i+2)
                       {
                           System.out.print((i+1)+ ",");
                       }
                       a.  1,2,3,4,5                                   b.  1 , 3 , 5 ,
                       c.  1,2,3,4,5,                                  d.  2,4,6,
                    2.  A do-while loop is executed ………………… .
                       a.  at least once                               b.  at least twice
                       c.   at most once                               d.  zero times
                    3.  A for loop is an ………………… controlled loop.
                       a.  exit                                        b.  entry



                                                                                                                       215
                                                                                                 Statements and Scope  215
   212   213   214   215   216   217   218   219   220   221   222