Page 262 - Computer science 868 Class 12
P. 262
Step 3: Initialise fact to 1
Step 4: Initialise i to 1
Step 5: Repeat Step 6 to Step 7 till i<=n
Step 6: Multiply fact by i and store the product in fact
Step 7: Increase i by 1
Step 8: Display fact
Step 9: Returns back to the caller program
Step 10: Stop.
2. Accept any number and check whether it is a Buzz number or not. A Buzz number is one which is divisible by
7 or ends with 7 in a method buzz().
Algorithm:
Step 1: Start.
Step 2: Call the method buzz and accept any number in num
Step 3: If num % 7=0 then go to Step 5
Step 4: If num % 10=7 then go to Step 5, else go to Step 7
Step 5: Display num “is a Buzz number”, go to Step 7
Step 6: Display num “is not a Buzz number”
Step 7: Returns back to the caller program
Step 8: Stop.
Let’s Revisit
♦ Methods are the block of statements in a program which performs a specific task and can be reused as and when required.
They are also called Functions.
♦ There are two types of methods. They are Built-in Methods and User-defined Methods.
♦ Built-in methods are already declared in the Java language and when required, the method is called and executed accordingly.
♦ Some of the type of built-in methods are Mathematical methods, String methods and Character methods.
♦ To use Mathematical methods in programs, we need to use “Math” class which resides in “java.lang” package.
♦ To manipulate the character type data, the Character wrapper class methods are used.
♦ To perform different types of operations on the String object, String methods are used.
♦ According to the requirement of the program, sometimes programmers need to create their own methods for the easiness of
the program. These methods are known as user-defined methods.
♦ The first line is known as the Method Header or Method Prototype.
♦ There are three types of access specifiers. They are public, private and protected.
♦ Static methods have the static keyword written along with the method prototype and If a method is declared under a class
without preceded by the word static, then it becomes the method of the instance of the class. They are known as instance
method.
♦ A pure function does not change the state of the object and an impure function changes the state of the object.
♦ In pass by Value, the values of actual parameters are copied to formal parameter where as in pass by reference , the actual
parameter and the formal parameter shares the same location in the memory.
♦ Function Overloading is the process of creating different functions with same name different number of parameters or
different data types of the parameters.
♦ Constructor is a member method with same name of the class that is used to initialise the instance variables of the objects.
♦ "this" operator is required to use the object of the class from the member method from the same class.
260260 Touchpad Computer Science-XII

