Page 314 - CA_Blue( J )_Class10
P. 314

38          ob.total_sal();
                39          ob.display();

                40      }
                41  }

              You will get the following output:














                              To define a class fibo with the following specifications:
                Program 5     Data Members
                              int n                :  last term of the series
                              int a,b,c            :  Used to store values in the series
                              Member Methods
                              fibo()               :  Constructor to initialize a=0,b=1,c=0 and n = 0
                              void accept(int lt)    :   Parameterised value to store lt to n
                              void print()         :  Displays the series upto n
                 1  import java.util.*;
                 2  class fibo

                 3  {   int n,a,b,c;

                 4      fibo()
                 5      {       a=0; b=1; c=0; n=0;    }

                 6      void accept(int lt)
                 7      {        n=lt;      }

                 8      void print()
                 9      {   int i;

                10          if(n==1)
                11              System.out.print(a);

                12          else if(n==2)
                13

                14              System.out.print(a + " , " + b);
                15          else

                16          {   System.out.print(a + " , " + b);
                17              for(i=3;i<=n;i++)
                18              {   c=a+b;



                312312  Touchpad Computer Applications-X
   309   310   311   312   313   314   315   316   317   318   319