Page 374 - Computer science 868 Class 12
P. 374

15               Scanner sc = new Scanner(System.in);
                16               System. out.println ("Enter number of terms");

                17               n = sc.nextInt();
                18           }
                19

                20           void generate()

                21           {
                22               System.out.print(x+","+y);
                23               int i;

                24               for(i=3; i<=n; i++)
                25               {

                26                   System.out.print(","+z);
                27                   x=y;

                28                   y=z;
                29                   z=y.concat(x);

                30               }
                31           }

                32
                33           public static void main()

                34           {
                35               FiboString obj=new FiboString();

                36               obj.accept();
                37               obj.generate();

                38           }
                39       }


              The output of the preceding program is as follows:
              Enter number of terms
              5
              a,b,ba,bab,babba

















                372372  Touchpad Computer Science-XII
   369   370   371   372   373   374   375   376   377   378   379