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

a=l*b;
                          System.out.println("Area : " +a);
                      }

                      void perimeter()
                      {
                          p=2*(l+b);
                          System.out.println("Perimeter : "+p);
                      }

                      public static void main ()
                      {
                          Scanner sc= new Scanner(System.in);
                          geometry_rectangle ob= new geometry_rectangle ();
                          int length, breadth;
                          System.out.println("Enter length of rectangle :");
                          length=sc.nextInt();
                          System.out.println("Enter breadth of rectangle :");
                          breadth=sc.nextInt();
                          ob.accept(length, breadth);                 // Actual Parameters
                          ob.area();
                          ob.perimeter();
                      }
                  }
              In the above example,
              •  The length and breadth are the actual parameters which contain two values respectively and the formal parameters
                 len and bre receive these values in the same order.
              Hence, we can now conclude as follows:
              •  Actual Parameters: The actual values that are passed directly or through the variables to the respective method at
                 the time of calling the method are called the actual parameters. They are defined in the calling method.
                In the above program, the actual parameters are length and breadth which are defined in the calling method.

                      ob.accept(length,breadth);
              •  Formal Parameters: The values sent by the calling method are received in the parameters described in the method.
                 These parameters that receive the values from the caller method are known as the formal parameters. They are
                 defined in the called method.
                In the above program, the formal parameters are len and bre which are defined in the called method.
                      void accept (int len, int bre);

                   8.5 DEFINING A FUNCTION
              There are three different ways of defining a function which are discussed as follows:
              a. The function does not take any value as parameters and does not return any value.
                For example,
                  import java.util.*;
                  class factor
                  {
                      void factor_num()
                      {
                          Scanner sc=new Scanner(System.in);
                  int  num,i;
                  for(i=1;i<=num;i++)
                  {
                      if(num%i==0)


                198198  Touchpad Computer Science-XI
   195   196   197   198   199   200   201   202   203   204   205