Page 220 - computer science (868) class 11
P. 220

42                  System.out.println(n+" is an Armstrong Number");
                43              else

                44                  System.out.println(n+" is not an Armstrong Number");
                45          }

                46
                47          public static void main()

                48          {
                49              armstrong ob= new armstrong();
                50              ob.input();

                51              ob.display();

                52          }
                53      }

              The output of the preceding program is as follows:
                Enter a number:
                153
                153 is an Armstrong Number


                Program 3      Define a class Fibo to print the Fibonacci Series with the following specifications:

                               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 initialise 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 up to n

                1       import java.util.*;

                2       class fibo
                3       {   int n, a, b, c;
                4           fibo()

                5           {

                6                a=0; b=1; c=0; n=0;
                7           }
                8           void accept(int lt)

                9           {
                10              n=lt;

                11           }





                218218  Touchpad Computer Science-XI
   215   216   217   218   219   220   221   222   223   224   225