Page 434 - Computer science 868 Class 12
P. 434

else if(j>i)
                          { System.out.println();
                          print(i+1,i+1);
                          }
                      else
                          { System.out.print(j);
                         print(i,j+1);
                      }}
                  4.  The following functions show() and calling() are a part of some class. Assume that the parameter n is greater than 1 when the
                    function is invoked. It returns the value 1 when true otherwise it returns 0. Show the dry run/working.    [ISC 2008]
                      void calling()
                      { int f=2;
                        show(n,f);
                       }
                      int show(int n, int f)
                      { if(n==f)
                          return 1;
                        if(n%f==0     || n==1)
                          return 0;
                        else
                          return(show(n,f+1));
                      }
                     i.  What will the function show() return when the value of n is 11?
                     ii.  What will the function show() return when the value of n is 27?
                    iii.  State in one line, what is function show() is doing?
                  5.  The following function is part of some class. What will be the method return if n = 10? Show working/dry run.
                      int func(int n)
                      {
                          if (n == 0)
                               return 0;
                          else if (n == 1)
                               return 1;
                          else if (n == 2)
                               return 1;
                          else
                               return 2*func(n-2) + func(n-3);
                      }
                  6.  The following method is a part of some class. What value will be returned if n = 3?
                   String bracket(int n) {
                        if (n == 0) return "{}";
                        String s = "";
                        for (int i = 0; i < n-1; i++)
                            s += bracket (i) + ", ";
                        return "{" + s + bracket (n-1) + "}";
                     }
                  7.  The Evil number is a special positive whole number that has an even number of 1 in its binary equivalent
                    6 is an evil number as its binary equivalent 110 has two 1
                     9 is an evil number as its binary value 1001 has two 1
                     15 is an evil number as its binary value 1111 has four 1
                     A class called Evilnum is defined to check if a number is evil number or not. Some of the members of the class are given
                    below:
                    Class name                        :   Evilnum
                     Data Members/Instance variables
                     num                              :  to store the number
                     Methods/Member functions
                     void getnum()                    :  accept number in num from the user



                432432  Touchpad Computer Science-XII
   429   430   431   432   433   434   435   436   437   438   439