Page 249 - ComputerScience_Class_11
P. 249
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:
BlueJ: Terminal Window - Java
Options
Enter a number:
1634
1634 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 whereas 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:
Program 3 Write a program to calculate area and perimeter of a rectangle using actual and formal
parameters.
1 import java.util.*;
2 class geometry_rectangle
3 {
4 int l, b, a, p;
5 void accept (int len, int bre) // Formal Parameters
6 {
7 l=len;
8 b=bre;
9 }
10 void area()
11 {
12 a=l*b;
13 System.out.println("Area : " +a);
14 }
Methods and Constructors 247

