Page 33 - IP
P. 33

(c) What will be an output of the following code if value of variable application is 1?    1

                   Switch (application)
                          {
                   case 0    :  jTextField1.setText("RDBMS");
                   case 1    :  jTextField1.setText("BROWSER");
                   case 2    :  jTextField1.setText("OS"); break;
                   case 3    :  jTextField1.setText("PHOTO EDITOR"); break;
                   default  :  jTextField1.setText("Application Software"); break;
                             }
                                                            OR
                (c) Re-write the above given code through if-else statements.

                (d) Anju, a beginner in java programming has written following code with some mistakes:    4
                        int k=0;
                        string s="Save Earth";
                        int l=s.length;
                        for(int i=0;k<l;i++)
                        {
                        jTextArea1.append(s+\n);
                        k++;
                        };
                   Help her in identifying and correcting the errors.
                   Convert the correct code into do while looping statement.

                                                          OR
                (d) Observe the given code:
                    int ctr=10;
                   while(ctr>5)
                   {
                   ctr=ctr-2;
                   }
                   Attempt the following questions based on the above given code:
                   i.  How many times the  above  given loop  will run and what  will be the value of ctr,
                   immediately after exiting from the loop.
                     ii.  Out  of  entry  controlled  or  exit  controlled loop,  above  given  loop  will  come  under
                   which category and why?

                (e) Study the following code and answer the questions that follow:                         2
                   String str="Green World, Clean World";
                   int len=str.length(),remain;
                   remain=100-len;
                   jTextField2.setText(str.toUpperCase());
                   jTextField3.setText(Integer.toString(remain)+" more charachters can be entered");

                     i. Predict the output displayed in text fields named jTextField2 and jTextField3 after
                       running the above code.
                     ii. Identify and name any two method of String class used in the above code.

                                                          OR

                (e) Explain the purpose of pow() method with the help of suitable java code. Also mention
                   that pow() method belongs to which class?



                                                            4
   28   29   30   31   32   33   34   35   36   37   38