Page 10 - IP
P. 10

(b)     What values will be displayed in JOptionPane when the following
                   code is executed ?                                                              2
                   int a=5, b = 2;
                              while (a < 20)
                              {
                                    a = a + b;
                                    b = a  b;
                   JOptionPane.showMessageDialog(null,a);
                             }
           (c)     Write the code given below using ‘for’ loop instead of ‘while’ loop :           2

                   int i=1;
                              while(i<=5)
                              {
                                  if(i * i == 4)
                                      jTextField1.setText(""+i);
                              i=i+1;
                             }
           (d)     Write the value that will be stored in variable a after execution of
                   the following code if :                                                         2

                   (i)    initial value of a is 8.
                   (ii)   initial value of a is 10.

                   int b = 9;
                   if (a > b)

                       a=a+5;
                     a=a+2;

           (e)     What  will  be  the  values  of  i  and  z  after  the  following  code  is
                   executed :                                                                      2
                   int i = 0;

                   int z = 10;
                                 do
                                 {

                                  i = i+2;
                                  z;

                                 }
                              while (i<10);

      90                                             6
   5   6   7   8   9   10   11   12   13   14   15