Page 267 - Computer science 868 Class 12
P. 267

System.out.println("CAKES=" + f.cakes);
                         }
                        }
                    18.  Read the program code given below, answer the questions that follow.
                        public class find {
                        public static void main() {
                       int number=-13;
                        if(number>0){
                       System.out.println("POSITIVE");
                        }else if(number<0){
                       System.out.println("NEGATIVE");
                        }else{
                       System.out.println("ZERO");
                        }
                        }
                        }
                    19.  The following function witty() is a part of some class. What will be the output of the function witty() when the value of n is
                       ‘SCIENCE’ and the value of p is 5. Show the dry run/working:

                       void witty (String n, int p)
                       {
                       if (p < 0)
                       System.out.println(" ");
                       else
                       {
                       System. out .println(n.charAt(p) + " . ");
                       witty (n, p - 1);
                       System.out.print(n.charAt(p));
                       }
                       }
                    20.  The following function is a part of some class that computes and sorts an array arr [] in ascending order using the bubble sort
                       technique. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by some statements/
                       expressions so that the function works properly:
                       void bubblesort (int arr [])
                       {
                       int i, j, k temp;
                       for (i = 0; ?1?; i ++)
                       {
                       for (j = 0; ?2?;j++)
                       {
                       if { arr[j] > ?3?)
                       {
                       temp = arr [j];
                       ?4? = arr [j + 1];
                       arr [j + 1] = ?5?;
                       }
                       }
                       }
                       }
                      (i)   What is the expression or statement at ?1?
                      (ii)   What is the expression or statement at ?2?
                      (iii)  What is the expression or statement at ?3?
                      (iv)  What is the expression or statement at ?4?
                      (v)  What is the expression or statement at ?5?


                                                                                                                       265
                                                                                                            Methods    265
   262   263   264   265   266   267   268   269   270   271   272