Page 45 - IP
P. 45

ii.     Above given loop will come under Entry controlled loop as in the above given
                         loop condition is being checked at the time of entering in the loop.
                         (1 Mark for  correct answer)
                         (1 Mark for  correct justification)

                  (e)      Study the following code and answer the questions that follow:                2
                         Study the following code and answer the questions that follow:
                         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
                         Explain the purpose of pow() method with the help of suitable java code. Also
                         mention that pow() method belongs to which class?

                  Ans:   i. GREEN WORLD, CLEAN WORLD
                         76 more charachters can be entered

                         ii. length(),toUpperCase()

                         ( ½ Mark for each correct answer)
                                                              OR
                         pow() method, a mathematical method, helps in calculating the power of any
                         number.
                         For example:
                         int num=2,power=4;
                         int ans=Math.pow(num,power);
                         t1.setText(""+ans);

                                                                   4
                         The above code will calculate the value of 2 and will give answer 16.
                         pow() method belongs to math class.

                  (f)   Mr.  Suman,  a  programmer  in  New  Era  Programming  World  has  designed  a  6
                        registration page for a hobby club as shown below:

























                                                            8
   40   41   42   43   44   45   46   47   48   49   50