Page 223 - Cs_withBlue_J_C11_Flipbook
P. 223

37          }
                  38          public static void main()

                  39          {
                  40              Scanner sc=new Scanner(System.in);

                  41              System.out.println("Enter a number : ");
                  42              n=sc.nextInt();

                  43              armstrong ob= new armstrong();
                  44              ob.input(n);

                  45              ob.display();
                  46          }

                  47      }

                 The output of the preceding program is as follows:
                 Output 1
                   Enter a number:
                   1634
                   1634 is an Armstrong Number
                 Output 2
                   Enter a number:
                   153
                   153 is an Armstrong Number
                 In the above program, the parts of a method are:
                 1. Method Headers: void input(int), boolean check_armstrong(), void display(), public static void main()

                 2. Access Specifiers: all are public (as nothing is mentioned).
                 3. Return  Type  and  Return  Statement:  Boolean  is  the  return  type  and  return  true  or  return  false  are  its  return
                   statements. Other methods do not return any value. So, no return statements and void is the return type.
                 4. Methods names:  input(), check_armstrong(), display(), main()

                 5. Parameter list:  num is the parameter in input(num) and the remaining methods do not have a parameter.
                 6. Body of the Method: All the methods contain some statements which execute to provide an answer.

                     9.4 ACTUAL AND FORMAL PARAMETERS
                 Before understanding what the actual and formal parameters are, let us take the following example:
                    import java.util.*;
                    class geometry_rectangle
                    {
                        int l, b, a, p;
                        void accept (int len, int bre)             // Formal Parameters
                        {
                            l=len;
                            b=bre;
                        }

                        void area ()
                        {

                                                                                                                       221
                                                                                              Methods and Constructors  221
   218   219   220   221   222   223   224   225   226   227   228